Search code examples
javascriptfor-loopecmascript-6let

For loop let scope stackblitz vs chrome dev tools


Why does the following code produce a different result in StackBlitz vs Chrome Dev Tools?

I would expect i to be undefined outside the for loop (agreeing with the Chrome Dev Tools result).

What is going on here with the Stackblitz result?


Stackblitz (blank ES6 project)

enter image description here


Chrome Dev Tools

enter image description here


Solution

  • StackBlitz transpiles code to ES5, thus changing let to var. The latter is function-scoped, so it's visible outside the loop.