Given this code
function foo() { var x = 1; function bar() { debugger; return x + 1; } return bar(); }
when i open the google chrome console and foo() starts, the console stops at the debugger line. If I type “x” in the console, I get a “Dug out ReferenceError: x not defined .
If I want to access x in the console, I have two options:
I noticed that when you put a debugger , and the code at some point gets access to the scope variable, I can access it in the console.
I found other topics like this one more or less asking the same question. Is there a better way to access closure variables?
Btw I am using Version 59.0.3071.104 (Official Build) (64-bit) for Debian 8.
Pablo source share