Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

console.dir — inspecting an object

console.dir displays a value using generic JavaScript object formatting; presentation details depend on the console implementation.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

console.dir(item)
console.dir(item, options)

console.dir(item, options) displays item using generic JavaScript object formatting, potentially allowing properties to be expanded. It returns undefined. This is a WHATWG-defined console API, not an ECMAScript language feature.

Both arguments are optional. options is an object containing implementation-specific formatting options; the standard defines no portable set of properties.

Unlike console.log, console.dir does not process formatting specifiers. console.dirxml prefers a DOM tree representation when available.

The example displays a nested object. Do not expect identical text or layout across consoles.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Inspect an object with console.dir</title>
</head>
<body>
  <p id="result" role="status"></p>
  <script>
    const profile = { name: 'Ada', settings: { theme: 'dark' } };
    const result = document.querySelector('#result');
    if (typeof console.dir === 'function') {
      console.dir(profile);
      result.textContent = `Open the DevTools Console and expand settings to inspect theme: ${profile.settings.theme}.`;
    } else {
      result.textContent = 'console.dir unavailable';
    }
  </script>
</body>
</html>

Result

Open the DevTools Console and expand settings to inspect theme: dark.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources