- Published
- Author
- Adithya HebbarSystem Analyst
util.inspect use-case:• Without
util.inspectJavaScript
const obj = {
name: "Adi",
age: 24,
details: { details1: { details2: { hobbies: "travelling" } } },
};
console.log(obj);
//Output: { name: 'Alice', age: 30, details: { details1: { details2: [Object] } } }• With
util.inspectCode
import util from "util";
const obj = {
name: "Adi",
age: 24,
details: { details1: { details2: { hobbies: "travelling" } } },
};
console.log(util.inspect(obj, { depth: null, colors: true }));
//Output: { name: 'Adi', age: 24, details: { details1: { details2: { hobbies: 'travelling' } } } }console.log doesn't show all details of complex objects, especially nested ones or hidden properties. util.inspect gives a complete and customizable view for better debugging and understanding.#javascript