2

Let's say I have a function foo, and I set a break point in console.log(c), and print a and b in chrome dev tool console. I can get a but I can not get b. I don't know why.

foo();

function foo(){
    var a = 2;
    var b = 3;
    bar(4);
    function bar(c) {
        console.log(a);
        // console.log(b);
        console.log(c);
    }
}   

console

Call Stack

Tina Chen
  • 2,010
  • 5
  • 41
  • 73
  • 5
    That's because `b` isn't used in the function, so v8 has already optimized the variable out of lookup by the time the debugger has reached the breakpoint – Patrick Roberts Mar 29 '18 at 02:47
  • Yeah, it is frustrating. If there's ever a variable in a higher scope I want to be able to inspect directly in my **Source** tab w/o having to use the **Scope** pane, I console log the values inside the intended scope-- this forces Chrome to keep them immediately available for inspection. Goofy, but it works. – Alexander Nied Mar 29 '18 at 03:23

0 Answers0