π Search Terms
function declaration statement
π Version & Regression Information
v 5.9.3
β― Playground Link
https://www.typescriptlang.org/play/?target=99#code/JYMwBAFALgTgrgUwJRgG4EMZgB5gLxgAMA3ALABQAxgPYB2AztQDYIB0T1A5hNksWAHoB1ANYUKIalggsoYYPiL8FAHjABmZQGotKDFgBWi4GSp1GLdlwgGUQhDBhT5tMDQC2AB2AsAXGCNgejA4egQAEzAAIwRJGARohGBaTjB0enpgTloAGjBaajAHJyxksHhaKGB3BLA68XJQSFhEFBA4WkoqujAQCBQAbwBfCX6hAqLHZzKPbxYwKpq8qLg5YunXCsWEfwBJV3pYYC6wd2pwhJoLvPbO7oY3dFc6JgBPRLALyiZMCLS5KDUTxgFioBBMMAbTIXNLRDiUERgIA
π» Code
if (true) var x = 0;
console.log(x); //ok
for (let i = 0; i < 3; i++) var j = i;
console.log(j) //error in compile: j is used before being assign, no error in runtime
if (true) function f() {}
f()//no error in compile time, but error in runtime: In strict mode code, functions can only be declared at top level or inside a block
π Actual behavior
π Expected behavior
Additional information about the issue
The questions above was raised only in academic purpose. I understand that there are no real use cases to apply code above.
π Search Terms
function declaration statement
π Version & Regression Information
v 5.9.3
β― Playground Link
https://www.typescriptlang.org/play/?target=99#code/JYMwBAFALgTgrgUwJRgG4EMZgB5gLxgAMA3ALABQAxgPYB2AztQDYIB0T1A5hNksWAHoB1ANYUKIalggsoYYPiL8FAHjABmZQGotKDFgBWi4GSp1GLdlwgGUQhDBhT5tMDQC2AB2AsAXGCNgejA4egQAEzAAIwRJGARohGBaTjB0enpgTloAGjBaajAHJyxksHhaKGB3BLA68XJQSFhEFBA4WkoqujAQCBQAbwBfCX6hAqLHZzKPbxYwKpq8qLg5YunXCsWEfwBJV3pYYC6wd2pwhJoLvPbO7oY3dFc6JgBPRLALyiZMCLS5KDUTxgFioBBMMAbTIXNLRDiUERgIA
π» Code
π Actual behavior
π Expected behavior
Additional information about the issue
The questions above was raised only in academic purpose. I understand that there are no real use cases to apply code above.