Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Why is this answer still getting upvotes?</h2> <p>Per <a href="https://stackoverflow.com/a/24694804/361684">Mikaël Mayer's answer</a>, this is no longer a problem, and my answer is obsolete (<code>go()</code> now returns <code>30</code> after mucking with the console). This was fixed in July 2013, according to the <a href="http://code.google.com/p/chromium/issues/detail?id=124206" rel="nofollow noreferrer">bug report</a> linked above in <a href="https://stackoverflow.com/questions/4603021/is-it-possible-to-change-javascript-variable-values-while-debugging-in-google-ch/4949829#comment22050829_4603021">gabrielmaldi's comment</a>. It alarms me that I'm still getting upvotes - makes me think the upvoter doesn't understand either the question or my answer.</p> <p>I'll leave my original answer here for historical reasons, but <strong>go upvote <a href="https://stackoverflow.com/a/24694804/361684">Mikaël's answer</a> instead</strong>.</p> <hr> <p>The trick is that you can't change a local variable directly, but you can modify the properties of an object. You can also modify the value of a global variable:</p> <pre><code>var g_n = 0; function go() { var n = 0; var o = { n: 0 }; return g_n + n + o.n; // breakpoint here } </code></pre> <p>console:</p> <pre><code>&gt; g_n = 10 10 &gt; g_n 10 &gt; n = 10 10 &gt; n 0 &gt; o.n = 10 10 &gt; o.n 10 </code></pre> <p>Check the result of <code>go()</code> after setting the breakpoint and running those calls in the console, and you'll find that the result is 20, rather than 0 (but sadly, not 30).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload