|
|
|
|
|
by scottmf
3253 days ago
|
|
You can technically still use var if you wish, but I'm not sure of any reasons to do so. When switching to let/const, bear in mind the difference in scope: var is function-scoped: (function () {
var x = 1;
})();
var x === undefined
let/const are block-scoped: if (true) {
var x = 1;
let y = 1;
const z = 1;
}
x === 1
y === undefined
z === undefined
|
|
if(..) { ... huge block of code .. var foo = 1; }
Means I do not have to scroll back and forth to declare and set the variables at different places.