Why without () this theres a delay,but with () function is called instantly without delaying for 3secnds.. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Why without () this theres a delay,but with () function is called instantly without delaying for 3secnds..

function onTimeout() { alert("hey maaa"); } var timer=setTimeout(onTimeout(),3000);

10th Mar 2017, 2:48 PM
suraj pandey
suraj pandey - avatar
1 Answer
+ 7
because with () you call the function instantly instead of setting a timeout for it without () you are passing the function to the setTimeout function which creates a timer for a given function that where the difference lies: passing a function is done without () calling a function is done with ()
10th Mar 2017, 7:37 PM
Burey
Burey - avatar