You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 19, 2018. It is now read-only.
This is a dramatic improvement over var, and a big reason why let and const have become popular features. This block scoping is probably something that CoffeeScript should have, separate from the feature of const that means “throw an error on reassignment.”
We could have both, via := and :== operators (or whatever two operators people think are best):
a := 1 would mean, “declare a at the top of this block using let, and on this line assign a with the value of 1.”
a :== 1 would mean, “declare and assign a on this line using const. If it gets reassigned later, throw an error.”
We don’t necessarily need the second operator, if we don’t care to give the “throw an error on reassignment” feature.
let has the same issue as var, in that its declaration is hoisted to its entire scope (what MDN refers to as the temporal dead zone), so let declarations should be grouped together at the top of their block scope similar to how var declarations are currently grouped at the top of their function scope. const must be declared and assigned on the same line, so it can’t get moved up.