Search code examples
javascriptgoogle-chromescopedeveloper-tools

How do I see the list of all variables in scope along with their values in Javascript using the Developer Tools on Google Chrome?


I tried using the following and it does give me a list of variables in scope. I also need to see their values on the console. Is it possible?

for(var b in window) { 
    if (window.hasOwnProperty(b)) 
        console.log(b);
}

Solution

  • You can get the value of b in window using the bracket notation window[b]:

    for(var b in window)
    { 
      if(window.hasOwnProperty(b)) {
        console.log(b);
        console.log(window[b]);
      }
    }