Question 5
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
console.log("scheduling");
setTimeout("console.log('reminder')", 500);
- A It prints reminder after 500 ms in Node.js
- B SyntaxError: strings cannot contain code
- C TypeError in Node.js: setTimeout needs a function (browsers eval the string, which is unsafe) – pass () => console.log("reminder") Correct
- D It prints scheduling twice
Correct Answer: Option C
The browser's string form works like eval and is blocked by most Content Security Policies; Node.js does not support it at all.
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!