3 ms·
I don't really see any edge cases in the interaction between let and var, can you provide an example? But yeah, using both var and let in the same function woul
by olavk 12y ago
I don't really see any edge cases in the interaction between let and var, can you provide an example? But yeah, using both var and let in the same function would be ugly. Probably you would want to stick with let in new code since there is no benefit to var over let. But obviously var has to remain in the language for backwards compatibility.
- seasoup 12y agoI 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.