I’m doing Blogvent, a challenge to blog every day through December 25th. Today’s prompt is:
Day 4: A browser DevTools trick. Show a lesser-known console method, network filter, or CSS debugging feature you rely on.
When logging to the console, always log an object.
I’ve shared this before, and use it all the time. Here’s an example:
const result = await getThings();
console.log({result});
Most engineers log the raw value:
console.log(result);
Logging the raw object has some significant flaws. If result is an empty
string, null, or undefined, the output will be invisible or an
inconsequential blip in your console. Misreading a logged statement and making
an incorrect assumption based on that is a classic debugging mistake.
Some engineers use a string label:
console.log('The result is: ', result);
That’s too much typing for me. Here’s the approved solution:
console.log({result});
This is superior because it prints an object with the key result and the
value of result. Here are some example outputs:
{ result: 'welcome' }
{ result: '' }
{ result: undefined }
{ result: null }
{ result: false }
{ result: { message: 'welcome', status: 'ok' } }
You can even keep adding things to the object! You’ll get the same behavior with each one:
console.log({rawDate, dispalyDate, responseCode});
This might print:
{
rawDate: '2026-12-04',
displayDate: 'December 4, 2026',
responseCode: 404,
}
These labels (“rawDate”, “displayDate”) are searchable, filterable strings in Devtools as well.
Note: You can see what I plan to write about each remaining day of Blogvent in the list of prompts.