I was debugging an application when I decided I wanted to know what properties a higher level-scoped object had.
To my surprise chrome didn't even recognise the variable existed!
I've managed to boil the code down to this:
var a = 1;
var b = 2;
(function() {
console.log(a);
debugger;
})()
EDIT it seems the scenario doesn't work (that is..it works without issue) when the above code is just used on its own either in the console or in a html file. I observed the issue in a complex application (see screenshot below) and see it in the jsfiddle, but not in a codepen. If anyone could confirm I'm not crazy (other than that one coworker I used their machine to prove to myself) that'd be great
With the console open, have a look at the fiddle.
Once it pauses itself (due to the debugger
breakpoint keyword) try to inspect b
. It doesn't know it exists. But it knows a
does, supposedly because it is mentioned in the immediate scope.
Firefox doesn't exhibit the same behaviour (when it's not busy misbehaving in its own way I discovered today..)
So what is going on?
All I can think of is v8 is optimising away references that aren't being used, but why would it do that?
I didn't think that would yield worthwhile performance gains.. Why does it do it even when the devtools are open, and is there a way to stop it?
Edit: nothing to do with fiddle or frames
I'm on Fedora running 46.0.2490.71 (64-bit) if that means anything