Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to display local scoped variable in chrome's javascript console

I'm using chrome's javascript console to debug some javascript. And often I'm using the interactive command line to display some variables. When I'm in a function (halted by a breakpoint), and type in the name of a parameter (in my case "result") in the command line it displays the value of the global scoped result instead of the local scoped result. Is there a way to tell chrome's command line to evaluate the local scoped or inner most scoped variable in stead of the global scoped variable?

cheers.

like image 877
dr jerry Avatar asked Nov 15 '22 05:11

dr jerry


1 Answers

Looks like you make some mistake. I try next example:

var b=1;
function foo() {
    var b=2;
    debugger
}
foo();

"b" is equal 2, even if you will declare one function inside another one, if you will declare "b" with "var" - you will see you want.

Any additional information? maybe you have an example of code?

like image 169
Xrumet Avatar answered Dec 10 '22 03:12

Xrumet