2 ms·
Javascript has C syntax but does not follow the C tradition of having one scope per block, instead having one scope per function. This is really unintuitive if
by ufo 13y ago
Javascript has C syntax but does not follow the C tradition of having one scope per block, instead having one scope per function. This is really unintuitive if you are used to how lexical scoping is done in other C-like languages and is the source of many common annoyances, like the closures-in-for-loops bug or needing to wrap your code in IIFEs[1] if you want to create a local scope or prevent variables from being global.
[1] - Immediately Invoked Function Expressions: (function(){ ... }())