Engineering ThoughtJanuary 2025
#CodeUtilize Explored: console.dir
Unleashing the Power of console.dir by exploring various object inspection techniques

// console.dir preview
Have you ever tried to look inside a complex object in your code, only to find a messy pile of data that's hard to read? Most of us start with the classic
console.log, but as our projects grow, we need better tools to "see" what's going on.In this guide, we'll explore how to become a "data detective" using different inspection techniques in JavaScript and TypeScript. Whether you're a seasoned pro or just starting out, these tips will save you hours of debugging time!
###๐ The Basic Approach: console.log
The quickest way to peek at data is
console.log. It's like taking a quick snapshot of a roomโgreat for a general idea, but you might miss the details hidden in the corners.playground.js
The Catch: Notice the
[Object] part? console.log often "hides" deeper information to keep the output short. For simple data, it's perfect. For complex "nested" data, we need more power.###๐ฌ The Deep Dive: util.inspect
If
console.log is a snapshot, util.inspect is a high-powered microscope. It allows you to tell the computer: "Show me everything, no matter how deep it's hidden!"playground.js
This ensures you see every single "room" in your data structure, beautifully colored for readability.
###๐ณ The Interactive Way: console.dir
My personal favorite is
console.dir. It creates an interactive, expandable tree. It's like having a digital map where you can click to open folders and see exactly what's inside.playground.js
In your browser's developer tools, this becomes a clickable list that makes exploring large datasets feel like second nature.
###๐ Which one should you use?
###๐ก Final Thought
Debugging doesn't have to be a headache. By choosing the right "lens" to look at your data, you can spot bugs faster and understand your system more deeply.
If you found this helpful, check out my GitHub for more technical guides and creative experiments.
Happy debugging!