2 ms·
From ES6 section, first thing I notice: > let is the new var. Constants work just like let, but can’t be reassigned. See: Let and const I say it once, I say i
by anacleto 8y ago
From ES6 section, first thing I notice:
> let is the new var. Constants work just like let, but can’t be reassigned. See: Let and const
I say it once, I say it one thousand times: "Let is not the new Var".
They certainly have some similar behaviors but surely they do communicate very different things to a developer who is reading the code.
let: "you shouldn't/can't edit outside this block scope"
var: "feel free to change me whenever you want inside this scope (whether it's global or function)
JS stuff aside, this is actually very helpful.
- ChrisSD 8y agoI think the point being made is that `var` used to be the default assignment operator due to a lack of better options. This has now changed. And it's debatable whether `var` is still useful given its "odd" (i.e. unexpected) behaviour. Personally I'd go further and say `const` should be used by default and `let` should be reserved for when you really need it.