4 ms·
> * Lexical scope natively without syntax or conventions I assume you mean over the alternative, dynamic scoping like in e-Lisp. But you realize that JavaScrip
by titzer 5y ago
> * Lexical scope natively without syntax or conventions
I assume you mean over the alternative, dynamic scoping like in e-Lisp. But you realize that JavaScript's scoping rules are entirely wonky, e.g. that "var" declarations are lifted to the function level?
- austincheney 5y agoTo be more specific the term is hoist which means the declarations are pushed to the top of the scope at run time for maximum availability, and var is function scoped instead of block scoped. Block scoping is often more specific because a function body is a block as well.
- errantspark 5y agoRight but we have `let` now which solves that problem.
- titzer 5y agoNot completely, `let` also has a weird temporal dead zone[1], which is basically a dynamic check. [1] https://www.freecodecamp.org/news/what-is-the-temporal-dead-zone/ https://www.freecodecamp.org/news/what-is-the-temporal-dead-...
- IshKebab 5y agoThat's a good thing, and I'm not sure what you mean about it being a dynamic check.
- titzer 5y agoIt's a dynamic error if you access a let-bound variable before it is actually initialized. In most other languages that have lexically-scoped declarations, it simply would not be visible. So I think JS's choice is actually a regression.
- hwillis 5y agovar is a terrible example of that. Just don't use it. A good example would be the scoping in for loops and maybe arrow functions. For loops are goofy but virtually never an issue, and arrow functions are awesome.
- deleted 5y ago[deleted]
- cush 5y agoThey were referring to `let`