JavaScript Console dir() Tutorial

In this section, we will learn what the console dir() method is and how to use it in JavaScript.

JavaScript Console dir() Method

The `dir()` method is used to print a navigable tree of the members of a JavaScript object on the browser console.

Console dir() Method Syntax:


Console dir() Method Parameter:

The method takes one argument, and that is a reference to the object that we want to print its content on the browser console in a navigable tree format.

Console dir() Method Return Value:

This method does not return a value.

Example: using Console dir() method in JavaScript

const obj = {

   firstName: 'John',

   lastName: 'Doe',

   email: '[email protected]',





Open the browser console to see the way `obj` is printed on the console.

Leave a Reply