console.log writes to stdout; console.error writes to stderr. In servers, separating logs from errors helps aggregators filter severity. process.stdin and process.stdout are streams for CLI tools.
Console helpers
console.log(a, b)— space-separated valuesconsole.table(arrayOfObjects)— tabular debug outputconsole.time('label')/console.timeEnd('label')— rough timingconsole.dir(obj, { depth: null })— nested object inspection
Exit codes
Uncaught exceptions exit with non-zero code. CLI tools convention: 0 success, 1 general error, other codes for specific failures (document yours in README).
Important interview questions and answers
- Q: stdout vs stderr?
A: stdout for normal output (pipeable); stderr for errors/diagnostics so pipelines can still capture clean data. - Q: console.log in production APIs?
A: Prefer structured loggers (pino, winston) with levels and JSON—raw console is fine for learning and scripts.
Self-check
- Which stream does
console.erroruse? - When is
console.tablehelpful?