3 ms·
even if block scope was better, its not worth having three ways to declare a variable. Most JS programmers do not know about scope and they do not declare varia
by z3t4 10y ago
even if block scope was better, its not worth having three ways to declare a variable. Most JS programmers do not know about scope and they do not declare variables, but if they do, they more likely mean it to belong to the function, like in VBscript or PHP, rather then to the if statement.
Explaining why you should declare variables is hard. Now I also have to explain block scope, and angel brackets now makes a huge difference!
if(...) // use angel brackets
foo = 1; // declare variables
if(foo) ...
- epmatsw 10y agoI really don't think that most JS programmers write code without declaring variables. Anyone using strict mode, ES6, or ESLint/JSLint/JSHint is already forced to declare variables appropriately. Personally, I think the benefits of let are worth killing off var. I have honestly never seen an example where hoisting has been more clear than the alternative (declaring variables before they're used).