News for hackers. Stuff that matters.
Re:Overview of JavaScript ES6 features by betenoire on Monday October 24, 2016 @01:04PM (#12780653)
const vs let is an "immutable by default" vs "mutable by default" type of difference. it's not just a style difference, it can help you write stateless code if you assume immutability.

but yeah.

Re:Overview of JavaScript ES6 features by z3t4 on Monday October 24, 2016 @02:34PM (#12781495)
Native objects in JavaScript are already immutable as in you can not change them, only create new objects. Const will not make your object immutable! Try this:

  const foo = {bar: 1}
  foo.bar = 2;
It will only avoid having the pointer re-pointed to another object. It's better to just try avoiding global variables, and use a naming convention like uppercase and/or underscore for constants and global variables.

Const is probably only meant for constants like the name suggests.

I think something like this is pretty safe from reassigning:

  {
    let foo = 1
    ...
  }
  ...
If you want more control over your properties, you can use the ES5 feature "defineproperty" where you can set writeable: false
Re:Overview of JavaScript ES6 features by hajile on Monday October 24, 2016 @05:07PM (#12782905)
You can call `Object.freeze()` if you want immutable properties.
Re:Overview of JavaScript ES6 features by fryan on Monday October 24, 2016 @02:49PM (#12781642)

    const foo = {bar: 1}
The only thing const about it is the reference `foo` cannot be reassigned:

    foo = something_else; // error
Unlike `const` in C++, `const` in javascript in not very useful in my opinion. `let` is shorter and more readable.
Re:Overview of JavaScript ES6 features by gotofritz on Monday October 24, 2016 @03:49PM (#12782207)
Even that is only true for shallow objects
Re:Overview of JavaScript ES6 features by betenoire on Monday October 24, 2016 @03:43PM (#12782129)
All true. But what I said was,

> it can help you write stateless code if you assume immutability

Re:Overview of JavaScript ES6 features by BinaryIdiot on Monday October 24, 2016 @01:16PM (#12780769)
> const vs let is an "immutable by default" vs "mutable by default" type of difference

Sorta. I mean you're right but at the same time if you're using const for an object or array then it doesn't really matter without `object.freeze()` because it's not immutable only the reference is and I don't think most JavaScript developers understand that (at least not most of the ones I've run into).

Re:Overview of JavaScript ES6 features by gotofritz on Monday October 24, 2016 @03:50PM (#12782210)
Note that Object.freeze only works for shallow objects