Why is the function executed immediately when I use setTimeout?

You’re calling the function immediately and scheduling its return value.

Use:

setTimeout(testFunction, 2000);
                       ^

Notice: no parens.

Leave a Comment