jskatas.org Continuously Learn JavaScript. Your Way.

Block scope: let declaration

let restricts the scope of the variable to the current block.

Donate to NGO Julenka. Support Ukranians in need. Julenka is an NGO which my brother founded in 2011 to support Ukranian families and kids in need.

let restricts the scope of the variable to the current block

let vs. var

  • var works as usual, it`s scope is the function
  • let restricts scope to inside the block

let usage

  • let use in for loops
  • create artifical scope, using curly braces