Skip to content Skip to sidebar Skip to footer

Calling Variables Defined In Outer Function From Inner Function With Debugger

From the jQuery docs javascript guide: Because local scope works through functions, any functions defined within another have access to variables defined in the outer function:

Solution 1:

Presumably this is an optimisation by the JavaScript engine. Since you're not referring to y within the inner function there is no need to hold on to it in the closure. This will allow it to be garbage collected when the outer function returns.

If you add a reference to y (for example console.log(x, y)) you can see the values of both x and y as you would expect.

isn't there some way to still call the variable y from the console inside the inner function?

Apparently not. You could just add a reference to y within inner while debugging (it doesn't have to do anything, any reference will do).


Post a Comment for "Calling Variables Defined In Outer Function From Inner Function With Debugger"