Recall & Review
beginner
What is a callback function in Node.js?
A callback function is a function passed as an argument to another function, which is then called after some operation completes. It helps handle asynchronous tasks.
Click to reveal answer
beginner
Explain the term 'callback hell'.
Callback hell happens when many callbacks are nested inside each other, making code hard to read and maintain, like a pyramid or 'arrow' shape.
Click to reveal answer
intermediate
Why does callback hell make code difficult to maintain?
Because deeply nested callbacks create complex, hard-to-follow code flow, making debugging and updates confusing and error-prone.
Click to reveal answer
intermediate
How can you avoid callback hell in Node.js?
You can avoid callback hell by using techniques like named functions, Promises, async/await, or modularizing code into smaller functions.
Click to reveal answer
beginner
Show a simple example of a callback function in Node.js.
Example:
function greet(name, callback) {
console.log('Hello ' + name);
callback();
}
greet('Alice', () => {
console.log('Greeting done');
});Click to reveal answer
What is the main purpose of a callback function in Node.js?
✗ Incorrect
Callbacks let you run code after an asynchronous task finishes, like reading a file or fetching data.
What does 'callback hell' usually look like in code?
✗ Incorrect
Callback hell is when callbacks are nested deeply, making code hard to read.
Which of these is NOT a way to avoid callback hell?
✗ Incorrect
Writing all code in one big callback causes callback hell, not avoids it.
In the callback pattern, when is the callback function called?
✗ Incorrect
The callback runs after the main asynchronous task completes.
What is a common problem caused by callback hell?
✗ Incorrect
Callback hell makes code complex and difficult to maintain.
Describe what a callback function is and why it is used in Node.js.
Think about how Node.js waits for tasks like reading files.
You got /3 concepts.
Explain what callback hell is and list two ways to avoid it.
Imagine a pyramid of functions inside functions.
You got /5 concepts.