Not every bug needs the whole nested result that console.dir() showed. Say the positive check in Joan’s parseAmount() goes missing in an edit, and the total drifts from the 125 she expects. Here’s how the Python you’d use maps onto console:
| Python | JavaScript |
|---|---|
print(f"{total=} {donor=}") |
console.log({ total, donor }) |
print(..., file=sys.stderr) |
console.error(...) |
one print() per record |
console.table(rows) |
traceback.print_stack() |
console.trace() |
Label Each Value With Braces
Wrap the names in braces. { total } is object shorthand for { total: total }, so the variable names become the labels:
Language: JavaScript
const total = 125;
const donor = "D-101";
console.log({ total });
console.log({ total, donor });
Each call logs an object:
Language: Program Output
{ total: 125 }
{ total: 125, donor: 'D-101' }