What is the purpose of dir method of console object

in Javascript?

The Purpose of the console.dir() Method in JavaScript

The console.dir() method in JavaScript is used to display an interactive list of the properties of a specified JavaScript object. It is similar to console.log(), but instead of logging the object in a stringified form, it displays the object's properties in an interactive list. This list can be expanded and collapsed, allowing the user to inspect the object's properties in more detail.

Syntax

The syntax for the console.dir() method is as follows:

console.dir(object);

Where object is the object whose properties you wish to inspect.

Example

Let's look at an example of how to use the console.dir() method.

const person = { name: 'John Doe', age: 30, address: { street: '123 Main St', city: 'New York', state: 'NY' } }; console.dir(person);

When this code is executed, the following output will be displayed in the console:

console.dir() output

As you can see, the console.dir() method displays an interactive list of the properties of the person object. This list can be expanded and collapsed, allowing the user to inspect the object's properties in more detail.

Frontend development