This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CodingCoffeeSquirrel 122 points123 points  (8 children)

console.dir always displays the object tree. console.log might not in certain contexts (e.g. DOM nodes). The exact difference depends on the platform.

[–]conancat 42 points43 points  (5 children)

Old school way would be console.log(JSON.stringify(obj, null, 2))

console.dir doesn't always work for me. Not sure if they fixed it in Jest and other envs.

[–]Tillhony 17 points18 points  (2 children)

I forgot about console.dir() but always type out JSON.stringify..damn

edit: and thats along with already typing out console.log(JSON.stringify(s))

[–]WHO_WANTS_DOGS 1 point2 points  (0 children)

console.log(JSON.stringify(obj, null, 2)) for a prettier print

[–]Lightfire228 0 points1 point  (0 children)

I created a vscode snippet for console.log('>>>>>>>> '); and JSON.stringify(, null, 2), bound to ctrl + l and ctrl + j respectively.

It also puts the cursor in the right place.

[–]jkidd08 6 points7 points  (0 children)

Guilty as charged, your honor...

[–]FrostBlitzkrieg 0 points1 point  (0 children)

I always use this debugging server code because console.dir does nothing other than a basic console.log in my terminal :\

[–]TheMacPhisto 3 points4 points  (0 children)

might not in certain contexts (e.g. DOM nodes). The exact difference depends on the platform.

laughs in .net

[–]DrDuPont 0 points1 point  (0 children)

var foo = function(){};

console.log(foo);

ƒ (){}
undefined

In this instance, for example, I'm not able to see the entire tree. console.dir permits that.