2

while playing with native modules in Chrome browser (a module is a script with type set to module) I've found a strange behavior. Having this code:

var a = 1;
let b = 2;
const c = 3;
debugger;
console.log(a, b, c);

There were no variables in local scope, but clearly there are (a, b, and c) as they are logged in the console.

enter image description here

Interestingly, adding a function that uses top-level variables makes them appear in the Scope panel:

var a = 1;
let b = 2;
const c = 3;
debugger;
function f() {
  console.log(a, b, c);
}
f();

enter image description here

Why is it like that?

marzelin
  • 10,790
  • 2
  • 30
  • 49
  • Constant folding perhaps? Chrome is able to do [strange optimisations](https://stackoverflow.com/questions/28388530/why-does-chrome-debugger-think-closed-local-variable-is-undefined) – Bergi Aug 31 '18 at 20:52

0 Answers0