tutorialstonight logo

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.


▶ 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.


▶ 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