I know that evalu setTimeoutcan take a string as a parameter (1st), and I know that it’s better not to use this. I'm just wondering why there is a difference:
!function() {
var foo = 123;
eval("alert(foo)");
}();
!function() {
var foo = 123;
setTimeout("alert(foo)", 0);
}();
the first will work, and the second will give an error: foo is not defined
How are they performed behind the scenes?
source
share