5 ms·
Actually it's not just lexical scoping. If you had pure lexical scoping, given the way the for statement works, you would expect it to show the same value beca
by ylyn 6y ago
Actually it's not just lexical scoping.
If you had pure lexical scoping, given the way the for statement works, you would expect it to show the same value because it is the same x being captured.
JS actually specifically handles a for (let ...) specially by creating a _copy_ of the variable. See the spec[1] (the third clause starting with for (LexicalDeclaration ...)).
[1]: https://www.ecma-international.org/ecma-262/11.0/index.html#sec-for-statement-runtime-semantics-labelledevaluation https://www.ecma-international.org/ecma-262/11.0/index.html#...