let
vs var
In recent past var
was the only way to declare variables
While var
worked it a lot of confusing issues that came along with it
let
was introduced in the latest release of Javascript, ES6 to address these issues
While var
is still in use for legacy codebases, it is a recommended best practice to use let
instead of var
going forward
// declaring a variable using var
var name = "Jen"
// declaring a variable using let (best practice)
let name = "Jen"
Click here for more information on the differences between let
and var