In with let
Learn why let is preferred over var with examples.
We'll cover the following...
let is the sensible replacement for var. Anywhere we used var correctly before, we can replace it with let. let removes the issues that plague var and is less error prone.
No redefinition
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, using let to redefine that variable will result in an error.
Example
Press + to interact
Javascript (babel-node)
'use strict';//BROKEN_CODElet max = 100;console.log(max);let max = 200;console.log(max);
Explanation
This example is identical to the one we covered in the previous lesson, except that var has been ...
Ask