Closures & Scope.
In JavaScript, var is function-scoped, not block-scoped. This often causes surprises with closures. Prefer let/const.
Problem with var:
Solution with let:
Closure example:
In JavaScript, var is function-scoped, not block-scoped. This often causes surprises with closures. Prefer let/const.
Problem with var:
Solution with let:
Closure example: