February 2018
Intermediate to advanced
298 pages
8h 22m
English
When you declare a variable using the var keyword that is already declared using the var keyword (in the same scope) then it's overwritten. Consider this example:
var a = 0;var a = 1;alert(a); // alerts 1function myFunction() { var b = 2; var b = 3; alert(b); // alerts 3}myFunction();
The result is as expected. But the variables created using the let keyword don't behave in the same way.
When you declare a variable using the let keyword that is already declared using the let keyword in the same scope, then it throws a SyntaxError exception. Consider this example:
let a = 0;let a = 1; // SyntaxErrorfunction myFunction() { let b = 2; let b = 3; // SyntaxError if(true) { let c = 4; let c = 5; // SyntaxError }}myFunction(); ...Read now
Unlock full access