In JavaScript, redeclaring a variable with var is permissible at any point within a program.
Example
var x = 2; // Now x is 2 var x = 3; // Now x is 3 |
Using let, it is not permissible to redeclare a variable within the same block.
Example
var x = 2; // Allowed let x = 3; // Not allowed { let x = 2; // Allowed let x = 3; // Not allowed } { let x = 2; // Allowed var x = 3; // Not allowed } |
Redeclaring a variable with let in another block is permitted.
Example
let x = 2; // Allowed { let x = 3; // Allowed } { let x = 4; // Allowed } |