News for hackers. Stuff that matters.
Re:Airbnb JavaScript Style Guide by orthoganol on Thursday July 02, 2015 @10:42PM (#9823111)
Why are they worried about working by reference on numbers?

  // bad
  var a = 1;
  var b = 2;

  // good
  const a = 1;
  const b = 2;
Re:Airbnb JavaScript Style Guide by epidemian on Friday July 03, 2015 @12:20AM (#9823443)
In JS `const` just means that you can't reassign that variable, not that the value it references can't change:

  const a = {foo: 5};
  a.foo = 42; // This is perfectly valid.
  a = 'nope'; // But this isn't. It raises a SyntaxError.
Re:Airbnb JavaScript Style Guide by orthoganol on Friday July 03, 2015 @05:31AM (#9824480)
The purpose of the code wasn't to illustrate how to use const.

It was to show how they want you to always use const with complex types.

Re:Airbnb JavaScript Style Guide by anselmoars on Friday July 03, 2015 @05:43AM (#9824519)
'const' is misleading, it doesn't set your variables as immutable. Fine for expression, but not for actual practicality.
Re:Airbnb JavaScript Style Guide by icebraining on Friday July 03, 2015 @06:20AM (#9824626)
It does set your variables as immutable, just not your values. It makes sense if you see variables in these languages for what they are: references to values.
Re:Airbnb JavaScript Style Guide by shredprez on Thursday July 02, 2015 @10:59PM (#9823166)
Assuming I'm not misunderstanding your question, it appears to cover that right above the snippet:

"Why? This ensures that you can't reassign your references (mutation), which can lead to bugs and difficult to comprehend code."

So it's not about working by reference but avoiding inadvertent reassignment and resulting unpredictability.

Re:Airbnb JavaScript Style Guide by orthoganol on Thursday July 02, 2015 @11:14PM (#9823226)
> Assuming I'm not misunderstanding your question

Numbers are not passed by reference.

It's a lazy example, that has the potential to confuse. I would agree with the downvoters I'm being petty, but c'mon... it's the very first thing you read in your JavaScript guide & it's flawed.

Re:Airbnb JavaScript Style Guide by beaner on Friday July 03, 2015 @12:40AM (#9823518)
You're right.