October 2017
Intermediate to advanced
280 pages
6h 50m
English
Another confusing point of JavaScript for developers with a different background is the variable scope in the language. In Java and C++, for example, we're used to the block lexical scope. This means that a given variable defined inside a specific block will be visible only inside that block and all of the nested blocks inside of it.
However, in JavaScript, things are a little bit different. ECMAScript defines a functional lexical scope that has similar semantics to the block lexical scope, but it uses functions instead of blocks. Let's take a look at the following code snippet:
// ch4/let/var.ts var fns = []; for (var i = 0; i < 5; i += 1) { fns.push(function() { console.log(i); }); } fns.forEach(fn => ...Read now
Unlock full access