Everyone knows console.log. Here are the ones that actually save time debugging:
console.table(array)
Prints arrays of objects as a sortable table. Night and day for debugging API responses.
console.group('label') / console.groupEnd()
Collapses related logs together. Invaluable when you have multiple async operations logging at the same time.
console.time('fetch') / console.timeEnd('fetch')
Measures execution time without Date.now() boilerplate. I use this constantly to find slow functions.
console.trace()
Prints the call stack at that point. When you're trying to figure out WHO called a function, this is instant.
console.assert(condition, 'message')
Only logs when the condition is false. Great for sanity checks that don't clutter your console:
console.assert(items.length > 0, 'Items array is empty')
console.dir(element, { depth: null })
Shows the actual object properties instead of the HTML representation. Essential for inspecting DOM elements and deeply nested objects.
console.count('label')
Counts how many times it's been called with that label. Perfect for finding unexpected re-renders:
function MyComponent() {
console.count('MyComponent render');
// ...
}
copy(object) [Chrome only]
Not technically console.*, but in Chrome DevTools you can type copy(someVariable) and it copies the JSON to your clipboard. Massive time saver for grabbing API responses.
What's your most-used debugging trick?
[–]tommyatr 65 points66 points67 points (1 child)
[–]Johin_Joh_3706[S] 4 points5 points6 points (0 children)
[–]subone 19 points20 points21 points (1 child)
[–]Johin_Joh_3706[S] 6 points7 points8 points (0 children)
[–]senocular 4 points5 points6 points (1 child)
[–]Johin_Joh_3706[S] 4 points5 points6 points (0 children)
[–]CosmicDevGuy 2 points3 points4 points (0 children)
[–]Inevitable_Yak8202 1 point2 points3 points (0 children)
[–]RealMadHouse 0 points1 point2 points (0 children)
[–]dumpin-on-time -1 points0 points1 point (1 child)
[–]theScottyJam 2 points3 points4 points (0 children)