4 ms·
So you are saying that there are race conditions currently? Are any of this race conditions actually required by the language spec? If not, I suspect that those
by pm24601 11y ago
So you are saying that there are race conditions currently? Are any of this race conditions actually required by the language spec? If not, I suspect that those race conditions will be eliminated.
- david-given 11y agoI believe that what the parent meant was that this: function f() { console.log(a); const a = 1; console.log(a); } ...actually returns this: undefined 1 So you get partially compile-time semantics (you can't assign to a) but partially run-time semantics (a only gets its value when initialised). Simply propagating the value of a's initialiser to all places where the variable is used is wrong, as this behaviour's required by the spec.
- AgentME 11y agoActually that code example should throw an exception when the first `a` is evaluated.
- nullz 11y agoIt doesn't in v8 -- what do you mean by `should`?
- egeozcan 11y agoIt's an implementation error. In Firefox, it correctly throws: > ReferenceError: can't access lexical declaration `a' before initialization
- titzer 11y agoNo, 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.
- Skinney 11y agoNo it shouldn't. `a` at the first console.log invocation IS undefined, so it is entirely correct.
- anamexis 11y agoNot 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-and-const-declarations http://people.mozilla.org/~jorendorff/es6-draft.html#sec-let...