I am using the following code in a function:
setTimeout("doSomething(var1)",10000);
But, I also have var1
available as global variable. After 10000 milliseconds, will it call the local var1
or the global var1
?
Donut
113k20 gold badges136 silver badges147 bronze badges
asked Apr 25, 2011 at 14:50
2 Answers 2
This:
setTimeout('doSomething(var1)', 10000);
will pass the global variable var1
,
And this:
setTimeout(function() { doSomething(var1); }, 10000);
will pass the local variable var1
.
Live demo: http://jsfiddle.net/simevidas/EQMaz/
answered Apr 25, 2011 at 14:55
Comments
It will pass the the global variable named var1
.
answered Apr 25, 2011 at 14:52
Comments
Explore related questions
See similar questions with these tags.
lang-js