Search Interview Questions | ![]() ![]() Click here and help us by providing the answer. ![]() Click Correct / Improve and please let us know. |
|
| ||||
JavaScript - Interview Questions and Answers for 'Let vs var in javascript' - 1 question(s) found - Order By Rating | ||||
| ||||
Ans. Var scopes the variable to the nearest function whereas Let scopes the variable to nearest block. For example - function printNumbers() { for(var i = 1; i < 3: i++){ console.log(i); } console.log(i); // works fine and will print 3 as i has a function scope and not local loop scope } | ||||
![]() | ||||
![]() ![]() ![]() | ||||
![]() | ||||