June 2018
Beginner
288 pages
6h 31m
English
let is the sensible replacement for var. Anywhere we used var correctly before we can interchange it with let. let removes the issues that plague var and is less error prone.
let does not permit a variable in a scope to be redefined. Unlike var, let behaves a lot like variable definitions in other languages that strictly enforce variable declarations and scope. If a variable is already defined, then using let to redefine that variable will result in an error, as in the next example.
| | 'use strict'; |
| | //BROKEN_CODE |
| | let max = 100; |
| | console.log(max); |
| | |
| | let max = 200; |
| | console.log(max); |
This example is identical to the one we saw earlier, except that var was replaced with let. The compiler ...
Read now
Unlock full access