tutorialstonight logo
A Platform To Learn To Code

Difference between console.log and console.dir


console.log: console.log most used logging method in javascript, it provides us access to browser's console where you can output any string, number, object, etc.

console.log

Try It

console.dir: console.dir method outputs the list of properties of object in an interactive manner. It represent the list of properties of object in a hierarchical manner.

console.dir

Try It

console.log vs console.dir:

  • console.log take direct reference of the object it is logging while console.dir makes a copy of object before logging.
  • Using console.log you can interact with document object (DOM) but using console.dir you can not.
  • console.log prints the object in an HTML like tree while console.dir prints the element in a JSON like tree.

console.log vs console.dir

Try It
difference between console.log and console.dir