The setTimeout()
accepts a function as a first parameter and the time as the second parameter. I hope you have heard of functions returning a function as well. So for that cases, you can also call the function there.
The moment you add ()
to any function, it calls it immediately. So you call the function and return nothing to execute to the setTimeout
.
Case 1
setTimeout(myFunc, 3000);
Here you are passing the function itself to get executed after 3 seconds.
Case 2
setTimeout(myFunc(), 3000);
Here you are passing the function's executed return value to get executed after 3 seconds.