Question 4
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
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!