LearnFrenzy
Sign in Take a free test

Callbacks · Callbacks MCQ · Question 8

Passing a callback correctly Answer, explanation & discussion

  • MCQ
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

Which line runs showAlert after 2 seconds?

  • A setTimeout(showAlert, 2000); Correct
  • B setTimeout(showAlert(), 2000);
  • C setTimeout("showAlert", 2000);
  • D setTimeout(2000, showAlert);
Correct Answer: Option A

showAlert() would run immediately and pass its return value. Strings are evaluated as code in browsers (and rejected by Node.js), and the order of arguments is callback, delay.

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