DEV Community

Discussion on: JavaScript Closure Simply Explained

Collapse
 
salyadav profile image
Saloni Yadav

let is a block scope. so the value of i gets captured. in case of var its a global scope/scope of where the function is called. so when the function actually executes, the var i value is the last standing value, which is not the case with let.