Why does the Chrome debugger get undefined when accessing variables in Closure?

the code:

function test4() { var x = 10; var y = 100; // inner referred x only function inner () { console.log(x); debugger; } // inner2 referred y to make sure y is in the scope of inner function inner2 () { console.log(y); } return inner; } var foo = test4(); foo(); 

y is in the inner region, and even only inner2 , which has never been used, refers to it. I checked the result in scope and x , y :

x and y in closure

But when I checked the variables in the clock panel and console, I can’t get all of them:

can't get y in watch panel

It is strange that y is in the area, but not detected when using the debugger. So, does this mean that the debugger cannot access a variable that is not used in the current context even in closing, or is it just an error? (My chrome version is 51.0.2704.103 m)

It looks like Why does the Chrome debugger consider the private local variable undefined? but not the same. Because inner2 in my code make sure y is in closure. And actually my question is the opposite of Louis to answer on that.

+8
javascript google-chrome
source share

No one has answered this question yet.

See similar questions:

130
Why does the Chrome debugger consider the private local variable undefined?

or similar:

130
Why does the Chrome debugger consider the private local variable undefined?
10
My function somehow does not have access to its parent closure and there are no variables. How?
5
Chrome debugger: unused variables not loaded in JavaScript closure
4
Access to a private (local) variable inside the closure area
2
PHP closing functions: why should closing be an anonymous function?
2
Chrome Dev Tool: View Variable Unavailable (Cannot Detect in Limit Area)
one
Does Javascript always cover scope variables?
one
Does using "bind" when returning a function create a closure?
one
Why the Closure javascript property does not work with the parent
0
why should a variable be created in this closure

All Articles