Accessing closure variables in the console : <p>Given this code</p>

<pre><code>function foo()
{
    var x = 1;

    function bar()
    {
        debugger;
        return x + 1;
    }

    return bar();
}
</code></pre>

<p>when I open the Google Chrome's console and and <code>foo()</code> gets executed, the console stops at the <code>debugger</code> line. If I type 'x' in the console, I get <strong>Uncaught ReferenceError: x is not defined</strong>.</p>

<p>If I want to access <code>x</code> in the console, I have two options:</p>

<ul>
<li>Under <em>Source</em> go to <em>Scope</em>, open <em>Closure</em>, make a right click on <code>x</code> and click <em>Store as Global Variable</em>. This will create a global variable <code>temp1</code> with which I can access <code>x</code>.</li>
<li><p>edit <code>bar</code> to</p>

<pre><code>function var()
{
    x;
    debugger;
    return x + 1;
}
</code></pre></li>
</ul>

<p>I noticed that when you put a <code>debugger</code> and the code accessed a scope variable at some point, then I can access it in the console.</p>

<p>I found other threads <a href="https://stackoverflow.com/questions/28388530/why-does-chrome-debugger-think-closed-local-variable-is-undefined">like this one</a> more or less aksing the same question. Is there a better way to access the closure variables?</p>

<p>Btw I use <code>Version 59.0.3071.104 (Official Build) (64-bit)</code> for Debian 8.</p>
