LearnFrenzy
Sign in Take a free test

Event Loop · Find the Error · Question 4

Error: the callback is called immediately Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 4 Back to Exercise

The code below stops with an uncaught error. Which statement correctly describes the problem?

main.js
function autosave() {
  console.log("saved");
}
setTimeout(autosave(), 1000);
  • A It prints saved after one second
  • B It prints saved twice
  • C autosave() runs at once and setTimeout receives undefined – Node.js throws TypeError: the callback must be a function; pass autosave, not autosave() Correct
  • D SyntaxError
Correct Answer: Option C

The parentheses call the function. Browsers silently ignore undefined; Node.js throws ERR_INVALID_ARG_TYPE.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links