4 ms·
I haven't done a deep study on let to know how it interacts with var. Maybe it's something simple and I don't know it yet but how does this work: var foo = "a
by seasoup 12y ago
I haven't done a deep study on let to know how it interacts with var. Maybe it's something simple and I don't know it yet but how does this work:
var foo = "abc";
function do ( foo ) {
foo = "def";
console.log( foo );
let foo = "bar";
console.log( foo );
var foo = "baz";
console.log( foo );
}
console.log( foo );
do( foo );
console.log( foo );
And of course var has to be around for backwards compatibility, but if the addition of let is being made to make variable declaration more intuitive or simpler then it is failing because var must be included. You cannot consider let in isolation and when considered in combination with var, it makes things more complicated.
- olavk 12y agoI would assume you get a compile-time error because you are declaring 'foo' twice. I guess you are right that the language is getting more complex because you are introducing a new way of declaring variables. However the added complexity in the language means you can write code which is less complex and error prone (if you consistently use 'let' instead of 'var'), and I think this is a fair trade-off given that backwards compatibility must be preserved.