Variables declared using the var keyword always possess Global Scope and cannot have block scope.
Example
Variables declared with var inside a { } block can be accessed from outside that block.
{ var x = 2; } // x CAN be used here |
Variables defined with let can not be redeclared, preventing accidental redeclaration of a variable already declared with let.
You cannot perform this action with let.
let x = “John Doe”; let x = 0; |
Variables defined with var can be declared again.
With var, you are able to do this:
var x = “John Doe”; var x = 0; |