$0.33

What's the difference between using “let” and “var” ?

Ask a question+
1

When should let be used over var?

add comment

1 Answer

1

The difference is scoping. var is scoped to the nearest function block, and let is scoped to the nearest enclosing block, which can be smaller than a function block. Both are global if outside any block.

Also, variables declared with let are not accessible before they are declared in their enclosing block. It will throw a ReferenceError exception.

Hayk Hovsepyan 650
add comment

Your Answer