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?

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.