JavaScript Asynchronous JS (Callbacks) Quiz
Answer 75 questions on asynchronous JavaScript callbacks: fundamentals, error-first patterns, execution order, callback hell, timers, DOM and I/O callbacks, higher-order functions, data passing, chaining, and modern replacements like Promises.
Question 1
What distinguishes asynchronous JavaScript from synchronous execution?
Question 2
What is a callback in JavaScript?
Question 3
Which statement best describes asynchronous vs synchronous flow?
Question 4
Why were callbacks historically important before Promises and async/await?
Question 5
What does this code print?
function greetLater(cb) {
console.log('Preparing greeting')
cb('Hello')
}
greetLater(message => console.log(message))Question 6
What are higher-order functions in the context of callbacks?
Question 7
Why is naming callbacks helpful?
Question 8
What happens here?
setTimeout(function cb() {
console.log('Later')
}, 0)
console.log('Now')Question 9
What is the callback queue?
Question 10
Which order is logged?
console.log('A')
setTimeout(() => console.log('B'), 10)
console.log('C')Question 11
What is the error-first callback pattern?
Question 12
What does this error-first callback do?
function readFile(cb) {
cb(new Error('Fail'), null)
}
readFile((err, data) => {
if (err) console.error(err.message)
else console.log(data)
})Question 13
Why can deeply nested callbacks become a problem?
Question 14
Which technique helps avoid callback hell?
Question 15
What is logged?
function asyncAdd(a, b, cb) {
setTimeout(() => cb(null, a + b), 5)
}
asyncAdd(2, 3, (err, sum) => {
if (err) return
console.log(sum)
})Question 16
Why does asynchronous code rely on the event loop?
Question 17
What is callback hell?
Question 18
What does this nesting illustrate?
doA(resultA => {
doB(resultA, resultB => {
doC(resultB, resultC => {
console.log(resultC)
})
})
})Question 19
Which practice improves callback readability?
Question 20
How do setTimeout and setInterval relate to callbacks?
Question 21
What prints here?
setInterval(() => console.log('tick'), 50)
setTimeout(() => console.log('stop'), 160)Question 22
Why should intervals usually be cleared?
Question 23
How can you pass data through callbacks?
Question 24
What is logged?
function fetchUser(id, cb) {
setTimeout(() => cb(null, { id, name: 'Ada' }), 20)
}
fetchUser(7, (err, user) => {
console.log(user.id, user.name)
})Question 25
Why use error-first callbacks instead of throwing exceptions?
Question 26
What happens here?
function getData(cb) {
setTimeout(() => cb(null, 'value'), 5)
}
getData((err, value) => {
if (err) return
setTimeout(() => console.log(value), 5)
})Question 27
What is the callback execution order for multiple timers with the same delay?
Question 28
Why should callbacks be pure when possible?
Question 29
What does the console show?
console.log('start')
setTimeout(() => console.log('timer'), 0)
Promise.resolve().then(() => console.log('microtask'))
console.log('end')Question 30
What best practice applies to callback error handling?
Question 31
Which order of logs occurs?
const fs = require('fs')
console.log('read start')
fs.readFile('file.txt', (err, data) => {
if (err) return console.error('error')
console.log('read complete')
})
console.log('after read call')Question 32
What role does libuv play in Node.js callbacks?
Question 33
How do DOM event callbacks work?
Question 34
What does this DOM callback log after a click?
button.addEventListener('click', event => {
console.log('Clicked', event.type)
})Question 35
What is a higher-order function in callback composition?
Question 36
Why is callback execution order important?
Question 37
What prints?
function first(cb) {
setTimeout(() => cb('first'), 30)
}
function second(cb) {
setTimeout(() => cb('second'), 10)
}
first(value => console.log(value))
second(value => console.log(value))Question 38
How do browsers ensure UI responsiveness with callbacks?
Question 39
Why must callback APIs document their invocation guarantees?
Question 40
What is logged?
const queue = []
function schedule(task) {
queue.push(task)
}
schedule(() => console.log('task1'))
schedule(() => console.log('task2'))
while (queue.length) {
const next = queue.shift()
next()
}Question 41
What are I/O callbacks in JavaScript?
Question 42
Why do Node.js callbacks usually receive (err, data)?
Question 43
Which order occurs?
function logLater(label) {
setTimeout(() => console.log(label), 0)
}
logLater('X')
logLater('Y')Question 44
What is the callback queue also known as?
Question 45
What is printed?
const results = []
function asyncPush(value, cb) {
setTimeout(() => {
results.push(value)
cb()
}, 5)
}
asyncPush('A', () => console.log(results.join(',')))Question 46
Why do callbacks often receive context objects?
Question 47
What is the event loop responsible for?
Question 48
What prints from this microtask example?
console.log('start')
Promise.resolve().then(() => console.log('microtask'))
setTimeout(() => console.log('timer'), 0)
console.log('end')Question 49
How can callbacks be debounced?
Question 50
Why should callback-based APIs document if callbacks may be called multiple times?
Question 51
How can data be carried between chained callbacks?
Question 52
What prints?
function first(cb) {
cb(null, 'A')
}
function second(value, cb) {
cb(null, value + 'B')
}
first((err, value) => {
second(value, (err2, combined) => {
console.log(combined)
})
})Question 53
What is an error aggregator callback?
Question 54
Why do higher-order utilities like async.series exist?
Question 55
What prints from this waterfall?
function step1(cb) {
setTimeout(() => cb(null, 'data1'), 5)
}
function step2(input, cb) {
setTimeout(() => cb(null, input + '-data2'), 5)
}
step1((err, result1) => {
if (err) return
step2(result1, (err2, result2) => {
if (err2) return
console.log(result2)
})
})Question 56
What is callback composition?
Question 57
Why is consistent error propagation important in callback chains?
Question 58
What prints from this parallel pattern?
function work(label, delay, cb) {
setTimeout(() => cb(null, label), delay)
}
const results = []
work('A', 30, (err, label) => {
results.push(label)
if (results.length === 2) console.log(results.join(''))
})
work('B', 10, (err, label) => {
results.push(label)
if (results.length === 2) console.log(results.join(''))
})Question 59
What is an inversion of control concern with callbacks?
Question 60
Why is it risky when callbacks run both sync and async depending on conditions?
Question 61
What prints from this inconsistent callback?
function maybeAsync(flag, cb) {
if (flag) {
setTimeout(() => cb('async'), 0)
} else {
cb('sync')
}
}
maybeAsync(false, value => console.log('first', value))
maybeAsync(true, value => console.log('second', value))Question 62
How can you ensure callbacks always run asynchronously?
Question 63
What is callback chaining?
Question 64
How does queueMicrotask relate to callbacks?
Question 65
Why were Promises introduced as a callback alternative?
Question 66
What is the callback-to-promise conversion process often called?
Question 67
What does util.promisify accomplish?
import { promisify } from 'node:util'
import { readFile } from 'node:fs'
const readFileAsync = promisify(readFile)
readFileAsync('note.txt', 'utf8').then(console.log)Question 68
Why might you still use callbacks instead of Promises?
Question 69
How does async/await relate to callbacks?
Question 70
What is a continuation-passing style (CPS) function?
Question 71
What prints from this promisified pattern?
function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms))
}
delay(5).then(() => console.log('done'))Question 72
Why is it easier to compose Promises than raw callbacks?
Question 73
How can callbacks be converted to async/await?
Question 74
What is a downside of callbacks compared to Promises?
Question 75
When transitioning from callbacks to Promises, what should you verify?
