Lesson content
Read, practise, then check your understanding
A callback is passed for later invocation. Array methods use synchronous callbacks; timers, events, and I/O often invoke asynchronously.
Contract clarity
function loadUser(id, callback) {
readRecord(id, (error, record) => {
if (error) return callback(error);
callback(null, normalize(record));
});
}
Node-style callbacks conventionally receive error first and must be called exactly once. Document timing, arguments, receiver, cancellation, and error propagation. Deeply nested callbacks obscure sequencing and cleanup; extract named functions or adapt to Promises. Callbacks remain ideal for events, local predicates, and APIs with repeated results.
Knowledge check
Answer every question correctly to complete this chapter.
0 of 10 checks passed
Your progress is saved on this device.