Callbacks — Node.js Technical Interview Questions & Answers
Callbacks
Callbacks
- Callbacks is a Node.js topic. In plain words you use it for read notes.txt in a script. Don’t start with a slogan — start with that picture.
- Smallest example: (err, data) => …. Type it, run it, and say what you see. If you can do that from memory, you know Callbacks.
- From the example next to this theory: Callbacks: find user 2, then list names.
- Trap: callback hell, no error-first. Fix that before you talk about advanced Node.js.
- Viva: what is Callbacks? Then show (err, data) => …. Then name the trap.
Technical Interview Tip: What is Callbacks? Show this: (err, data) => …. Trap: callback hell, no error-first.
Code Examples for Callbacks
Callbacks — working example
// Callbacks
const users = [
{ id: 1, name: "Asha" },
{ id: 2, name: "Ravi" },
];
function findUser(id) {
return users.find((u) => u.id === id) ?? null;
}
console.log(findUser(2));
console.log(users.map((u) => u.name));Callbacks: find user 2, then list names. Say both prints.
How to Explain Callbacks to an Interviewer
What is Callbacks?
Used for read notes.txt a script Not just the heading
Give one small example of Callbacks.
(err, data) => … Callbacks: find user 2, then list names
What mistake do beginners make with Callbacks?
callback hell, no error-first Show the fix
Where do you use Callbacks?
a script read notes.txt