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

James Estrada
James Estrada
15,058 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.

1 Answer

Steven Parker
Steven Parker
134,115 Points

In the past, the behavior was quite difference, 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.