setInterval and window.onload problem
javascript, setinterval
Solution
Using a string command in `setInterval()` will try to look for the function in the global (window) scope, but since the function is defined in a local scope, it won't be found. You should pass the function itself to `setInterval()` instead.
window.onload = function() {
function foo() {
alert("test");
}
setInterval(foo, 500);
}
Problem
I have this code ``` window.onload = function() { function foo() { alert("test"); } setInterval("foo()",500) } ``` Which returns undefined...When i use it outside the window.onload it works. Can anyone explain me why?