I'm trying to write a simple code with a setTimeout
, but the setTimeout
just won't wait the time it's supposes to and the code execute immediately. What am I doing wrong?
setTimeout(testfunction(), 2000);
You're calling the function immediately and scheduling its return value.
Use:
setTimeout(testFunction, 2000);
^
Notice: no parens.