console.log(obj): In toString() representation — format ngắn gọn, readable.
console.dir(obj): In **interactive hierarchical listing** của properties — có thể expand/collapse nested object, xem prototype, getter/setter.
Ví dụ
const obj = { a: 1, b: { c: 2 } };
console.log(obj); // { a: 1, b: { c: 2 } }
console.dir(obj); // ▼ { a: 1, b: ▼ { c: 2 } } (expandable trong DevTools)
Khi nào dùng cái nào?
console.log: Debug nhanh, log message, primitive, object đơn giản.console.dir: Inspect object phức tạp, DOM element (xem property vs attribute), prototype chain.
Tip: console.log('%o', obj) trong Chrome cũng cho interactive object view.