My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Block Scoping in JavaScript

Murad Sofiyev's photo
Murad Sofiyev
·Feb 12, 2019

Hey

for(let i  = 0; i<3; i++) {
   setTimeout(() => {
     console.log(i);
  })
}

Why this is return 0,1,2 I know If I change let to var this is return 3 times 3. But What is going with let. Actually first time I think every loop time I redeclared but I think this is not true. Someone can explain what is going on here?