News for hackers. Stuff that matters.
Re:How necessary are var, let, and const? by AgentME on Monday June 01, 2015 @03:51PM (#9641635)
Actually that code example should throw an exception when the first `a` is evaluated.
Re:How necessary are var, let, and const? by nullz on Monday June 01, 2015 @04:28PM (#9641906)
It doesn't in v8 -- what do you mean by `should`?
Re:How necessary are var, let, and const? by egeozcan on Monday June 01, 2015 @04:54PM (#9642083)
It's an implementation error. In Firefox, it correctly throws:

> ReferenceError: can't access lexical declaration `a' before initialization

Re:How necessary are var, let, and const? by titzer on Tuesday June 02, 2015 @04:51AM (#9644653)
No, legacy const is not spec'd by ES5. It behaves differently in FireFox and V8 because it was added at different times with different semantics in the live range hole case. In strict mode, it will throw on V8 as well.
Re:How necessary are var, let, and const? by Skinney on Monday June 01, 2015 @04:54PM (#9642077)
No it shouldn't. `a` at the first console.log invocation IS undefined, so it is entirely correct.
Re:How necessary are var, let, and const? by anamexis on Monday June 01, 2015 @07:33PM (#9642929)
Not according to the spec[1]:

> The variables are created when their containing Lexical Environment is instantiated but may not be accessed in any way until the variable’s LexicalBinding is evaluated.

I.e. given a variable declared with `const`, you may not access it before it is set.

[1] http://people.mozilla.org/~jorendorff/es6-draft.html#sec-let...