July 2017
Intermediate to advanced
300 pages
5h 43m
English
In the old days, we used to always go with the var statement for variable declarations. ES2015 introduces two new declaration variables--let and const. The var statement declares a variable in a function scope:
(function(){ var foo = 1; if ( true ) { var foo = 2; console.log( foo ); } console.log( foo ); }());
$ node es6.js22
A variable declared with var (foo) spans the entire function scope, meaning that every time we reference it by name, we target the same variable. Both let and const operate on block scopes (if statement, for/while loops, and so on) as shown:
(function(){ let foo = 1; if ( true ) { let foo = 2; console.log( foo ); } console.log( foo ); }());
$ node es6.js21
As you can see from the preceding ...
Read now
Unlock full access