JavaScript · Junior · Question 4 of 75
How does let differ from var?
- ✓Correct answer:
letis scoped to a{}block,varto a function - 2
letis scoped to a function, whilevaris scoped to a{}block - 3No difference:
letis just a new name forvar
Explanation
A var declared inside an if or for is visible throughout the function. Also, var is hoisted with the value undefined and becomes a window property at the top level, while let and const are in the "temporal dead zone" until declared.