3 ms·
Why so much let? Are you supposed to only use let now? I thought it had a very specific use (like wanting a local variable in a loop).
by Kiro 12y ago
Why so much let? Are you supposed to only use let now? I thought it had a very specific use (like wanting a local variable in a loop).
- whostolemyhat 12y agoI think let is supposed to replace var completely. There's a brief mention of this in a book I was reading the other day (Understanding ES6: https://leanpub.com/understandinges6/read/ https://leanpub.com/understandinges6/read/ ) but no citation of where that decision comes from.
- _ZeD_ 12y agoyou want everything to be local. local should be the default. Thou shalt not be implicitly global.
- ahoge 12y ago> Are you supposed to only use let now? Yes, if you can use `let`, there is no reason whatsoever to use `var` ever again. If you want the `var` behavior, just put your declaration at the very top of the innermost function. With most code conventions, that's where you'd put a `var` declaration anyways. For what it's worth, Crockford also recommended to use `let` exclusively as soon as you can.