Console — Node.js Technical Interview Questions & Answers
Console
Console
- console.log prints. console.error for errors (stderr). console.table for a small array of objects. In production, a logger (pino/winston) is better than log in a hot loop.
- Trap: console.log(hugeObject) in a request handler thousands of times.
Technical Interview Tip: console.log('marks', marks);
Code Examples for Console
Console — working example
// Console
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));Console: find user 2, then list names. Say both prints.
How to Explain Console to an Interviewer
console.error vs log?
error goes to stderr log to stdout