setTimeout() with string or (anonymous) function reference? speedwise [closed]

There’s a third faster/simpler option:

window.setTimeout(func, 100);

…strictly relating to your question, the second is faster, as it’s still a reference – not an evaluation, which is always fairly expensive. As for the semicolon, yes it’s a good practice to always use them. They should never have been optional in my opinion, but plenty will disagree with me here. You can’t really argue against being explicit in your code, that’s always a good thing.

Leave a Comment