For the following snippet placed at the top level: do { let w = "banana"; function foo(){ w = "bar"; } foo(); console.log(w); } while(0) JSC prints "banana", instead of "bar".
<rdar://problem/90639204>
This seems to only happen when strict mode is off. The following code doesn't reproduce the issue in jsc shell: "use strict"; do { let w = "banana"; function foo() { w = "bar"; } foo(); print(w); } while (0); But this code does: do { let w = "banana"; function foo() { w = "bar"; } foo(); print(w); } while (0);
The variable is not even visible within the function: do { let w = "banana"; function foo(){ console.log(w); } foo(); } while(0) Result (unexpected): ReferenceError: Can't find variable: w Unlike with arrow function: do { let w = "banana"; foo=()=>{ console.log(w); }; foo(); } while(0) Result (as expected): banana