Using let in the initialization part of the for loop used in the function foo() leads to incorrect output.
Input:
function foo() {
let len = 0;
for (let i = 0; i < 2; i++) {}
return len;
}
Output:
"use strict";function foo(){for(var b=0;2>b;b++);return a}
The returned variable a is not defined. The function foo() must always return 0.
Demo: https://babeljs.io/repl/#?babili=true&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&browsers=&builtIns=false&code=function foo() { let len %3D 0%3B for (let i %3D 0%3B i < 2%3B i%2B%2B) {} return len%3B}
Using
letin the initialization part of theforloop used in the functionfoo()leads to incorrect output.Input:
Output:
The returned variable
ais not defined. The functionfoo()must always return0.Demo:
https://babeljs.io/repl/#?babili=true&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&targets=&browsers=&builtIns=false&code=function foo() { let len %3D 0%3B for (let i %3D 0%3B i < 2%3B i%2B%2B) {} return len%3B}