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.
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();
Why is it like that?