LearnFrenzy
Sign in Take a free test

Callbacks · Exercise 1 of 4

Callbacks Callbacks MCQ

  • 15 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript callbacks: synchronous and asynchronous callbacks, setTimeout, error-first callbacks, callback hell, inversion of control, this, consistent timing, async errors, parallel tasks and promisify. Pick an option to check your answer instantly.

Question 1 Easy

What is a callback in JavaScript?

A A function that calls itself
B A function that returns a promise
C A function that runs only on page load
D A function passed to another function, which calls it when appropriate
Question page & discussion
Question 2 Easy

Is the callback passed to arr.forEach synchronous or asynchronous?

A Asynchronous – it runs after the current code
B It depends on the array length
C It runs in a separate thread
D Synchronous – all calls finish before forEach returns
Question page & discussion
Question 3 Easy

When does the callback in setTimeout(fn, 0) run?

A Immediately, before the next line
B After the currently running code (and pending microtasks) have finished
C Never – 0 ms disables the timer
D Exactly 0 ms later, interrupting other code
Question page & discussion
Question 4 Easy

In Node.js-style callbacks, what is the first parameter?

A An error object, or null when the operation succeeded
B The result of the operation
C The callback itself
D A status code
Question page & discussion
Question 5 Easy

What is "callback hell"?

A Deeply nested callbacks for sequential asynchronous steps, which are hard to read and maintain
B A callback that throws an error
C A callback that is never called
D Calling too many synchronous callbacks
Question page & discussion
Question 6 Medium

Which approach does not help with callback hell?

A Splitting steps into named functions
B Adding more anonymous callbacks inline
C Using promises with then chains
D Using async/await
Question page & discussion
Question 7 Hard

What does "inversion of control" mean for callbacks?

A You give your continuation to other code, which decides whether, when and how many times it is called
B The callback controls the caller's variables
C Callbacks always run in reverse order
D The browser decides the order of all functions
Question page & discussion
Question 8 Easy

Which line runs showAlert after 2 seconds?

A setTimeout(showAlert, 2000);
B setTimeout(showAlert(), 2000);
C setTimeout("showAlert", 2000);
D setTimeout(2000, showAlert);
Question page & discussion
Question 9 Medium

What does setTimeout(greet, 100, "Asha", "Hi") do?

A Calls greet("Asha", "Hi") after 100 ms
B Calls greet() and ignores the strings
C Throws a TypeError
D Calls greet three times
Question page & discussion
Question 10 Medium

Inside a method, why does setTimeout(function () { this.count++; }, 0) not update the object's count?

A setTimeout freezes objects
B count is private
C Timers cannot change numbers
D The regular callback gets its own this from how the timer calls it, not the method's this – use an arrow function
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links