All quizzesEasy
Promises & Callbacks
Preview — 3 of 10 questions
What best describes asynchronous code in JavaScript?
javascript
console.log("Start");
setTimeout(() => {
console.log("Timer done"); // runs later
}, 1000);
console.log("End"); // runs immediately — doesn't wait
// Output:
// Start
// End
// Timer done (after 1 second)ACode that runs only in a separate thread
BCode that blocks execution until it completes
CCode that starts an operation and allows other code to continue running while waiting for the result
DCode that only works in Node.js, not in browsers
What is the output of this code?
javascript
console.log("A");
setTimeout(() => console.log("B"), 0);
console.log("C");AA B C
BA C B
CB A C
DC A B
What best describes a callback function?
javascript
function greet(name, callback) {
console.log("Hello, " + name);
callback(); // calls the callback after greeting
}
function sayBye() {
console.log("Goodbye!");
}
greet("Alice", sayBye);
// Output:
// Hello, Alice
// Goodbye!AA function that runs immediately when defined
BA function that is passed as an argument to another function to be called at a later time
CA function that only works with setTimeout
DA function that returns another function
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.