0

hi i have small doubt in understanding the difference of the following.

the following code did not worked:-

window.setTimeout(hello(),3000);
function hello(){
    alert("ju");
}

But the following code worked fine:-

window.setTimeout(function(){hello();},3000);
    function hello(){
        alert("ju");
    }

So what is the difference between the two. In the first code snippet i have called a function directly in setTimeout. In the second code snippet i have written an anonymous function and have called my function inside it. The first one did not worked and second one worked fine. So what is the difference and how to understand this?

2
Contributors
2
Replies
11
Views
3 Years
Discussion Span
Last Post by yaragalla_mural
1
window.setTimeout(hello,3000);
function hello(){
    alert("ju");
}

Call back function can not be called , what u have written with () is calling function.

Just pass name of function.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.