Using the var
keyword to redeclare a variable inside a block also affects the variable outside the block, potentially causing issues.
Example
var x = 10; // Here x is 10 { var x = 2; // Here x is 2 } // Here x is 2 |
This issue can be avoided by using the let
keyword, as re-declaring a variable inside a block does not impact the variable outside the block.
Example
let x = 10; // Here x is 10 |