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
setTimeout(testfunction(), 2000);
You're calling the function immediately and scheduling its return value.
Use:
setTimeout(testFunction, 2000); ^
Notice: no parens.
1.4m articles
1.4m replys
5 comments
57.0k users