← Back to companies
[ OK ] Loaded —
[ INFO ]
$ cd
$ ls -lt
01
02
03
04
05
$ ls -lt
01
02
03
04
05
user@intervues:~/$
What is the output of the following code? What changes if we use let instead of var?
javascript for (var i = 0; i < 5; i++) { setTimeout(() => console.log(i), 100); } console.log(i);
Expected Understanding:
var is function-scoped, let is block-scopedWith var:
var i is hoisted and all callbacks share the same iWith let:
let i creates a new binding for each iteration