Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics 2017 Building a Command Line Application Making a GET Request with https

James Estrada
seal-mask
.a{fill-rule:evenodd;}techdegree
James Estrada
Full Stack JavaScript Techdegree Student 25,866 Points

console.dir() vs console.log()

I'm using VS Code and I don't see any difference in the console whenever I use console.dir() or console.log(). According to this stackoverflow solution: https://stackoverflow.com/questions/11954152/whats-the-difference-between-console-dir-and-console-log I should see a tree representation of the output with console.dir(), but I see the same thing with both methods even with the example of the arrays the solution suggested. Is console.dir() a method I should use instead of console.log() whenever I use Node.js? Because I have not seen this method used in any other previous Treehouse courses from the Full Stack JavaScript track until this Node.js Basics course.

2 Answers

Steven Parker
Steven Parker
231,261 Points

In the past, the behavior was quite different, particularly when logging object contents, but I've noticed that newer JavaScript engines have expanded the functionality of "console.log" so there isn't much different from "console.dir" anymore.

Routine Poutine
Routine Poutine
26,050 Points

Should console.dir() be deprecated if console.log() can replace it?

Steven Parker
Steven Parker
231,261 Points

I haven't checked on the recent official language specs. It could be that the extra features are not required by the spec, and might not be implemented the same way in all browsers. In that case, official deprecation is probably not appropriate at this time.