recursal/MDN huggingface dataset:
console: dir() static method
============================

The **`console.dir()`** static method displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.

In other words, `console.dir()` is the way to see all the properties of a specified JavaScript object in console by which the developer can easily get the properties of the object.

**Note:** This feature is available in Web Workers

![A screenshot of the Firefox console where console.dir(document.location) is run. We can see the URL of the page, followed by a block of properties. If the property is a function or an object, a disclosure triangle is prepended.](/en-US/docs/Web/API/console/dir_static/console-dir.png)

Syntax
------


```js
dir(object)
```

### Parameters

`object`

A JavaScript object whose properties should be output.

### Return value

None (`undefined`).

Specifications
--------------

| Specification |
| --- |
| Console Standard # dir |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.dir()`
* Node.JS documentation for `console.dir()`
* Google Chrome's documentation for `console.dir()`
console: dirxml() static method
===============================

The **`console.dirxml()`** static method displays an interactive tree of the descendant elements of the specified XML/HTML element. If it is not possible to display as an element the JavaScript Object view is shown instead. The output is presented as a hierarchical listing of expandable nodes that let you see the contents of child nodes.

Syntax
------


```js
dirxml(object)
```

### Parameters

`object`

A JavaScript object whose properties should be output.

### Return value

None (`undefined`).

Specifications
--------------

| Specification |
| --- |
| Console Standard # dirxml |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.dirxml()`
* Node.JS documentation for `console.dirxml()`
* Google Chrome's documentation for `console.dirxml()`
console: timeLog() static method
================================

**Note:** This feature is available in Web Workers

The **`console.timeLog()`** static method logs the current value of a timer that was previously started by calling `console.time()`.

Syntax
------


```js
timeLog()
timeLog(label)
timeLog(label, val1)
timeLog(label, val1, /\* …, \*/ valN)
```

### Parameters

`label` Optional

The name of the timer to log to the console. If this is omitted the label "default" is used.

`valN` Optional

Additional values to be logged to the console after the timer output.

### Return value

None (`undefined`).

Description
-----------

The `console.timeLog()` method logs the current value of a timer.

The method can be passed the name of a timer. This will attempt to log the value of a timer created with that name in a previous call to `console.time()`:


```js
console.time("reticulating splines");
reticulateSplines();
console.timeLog("reticulating splines");
// reticulating splines: 650ms
```


If the timer name is omitted, then the timer is named `"default"`:


```js
console.time();
reticulateSplines();
console.timeLog();
// default: 780ms
```



```js
console.time("default");
reticulateSplines();
console.timeLog();
// default: 780ms
```


If there is no corresponding timer, `console.timeLog()` logs a warning like:
```

Timer "timer name" doesn't exist.
```


You can log additional values to the console after the timer output:


```js
console.time();
reticulateSplines();
console.timeLog("default", "Hello", "world");
// default: 780ms Hello world
```


See Timers in the documentation for more details and examples.

Examples
--------


```js
console.time("answer time");
alert("Click to continue");
console.timeLog("answer time");
alert("Do a bunch of other stuff…");
console.timeEnd("answer time");
```


The output from the example above shows the time taken by the user to dismiss the first alert box, followed by the cumulative time it took for the user to dismiss both alerts:
```

answer time: 2542ms debugger eval code:3:9
answer time: 4161ms - timer ended
```


Notice that the timer's name is displayed when the timer value is logged using `console.timeLog()` and again when it's stopped. In addition, the call to `console.timeEnd()` has the additional information, "timer ended" to make it obvious that the timer is no longer tracking time.

Specifications
--------------

| Specification |
| --- |
| Console Standard # timelog |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `console.time()`
* `console.timeEnd()`
* Node.JS documentation for `console.timeLog()`
console: group() static method
==============================

The **`console.group()`** static method creates a new inline group in the Web console log, causing any subsequent console messages to be indented by an additional level, until `console.groupEnd()` is called.

**Note:** This feature is available in Web Workers

Syntax
------


```js
group()
group(label)
```

### Parameters

`label` Optional

Label for the group.

### Return value

None (`undefined`).

Examples
--------

You can use nested groups to help organize your output by visually associating related messages. To create a new nested block, call `console.group()`. The `console.groupCollapsed()` method is similar, but the new block is collapsed and requires clicking a disclosure button to read it.

To exit the current group, call `console.groupEnd()`. For example, given this code:


```js
console.log("This is the outer level");
console.group();
console.log("Level 2");
console.group();
console.log("Level 3");
console.warn("More of level 3");
console.groupEnd();
console.log("Back to level 2");
console.groupEnd();
console.log("Back to the outer level");
```


The output looks like this:

![A screenshot of messages nested in the console output.](/en-US/docs/Web/API/console/group_static/nesting.png)

See Using groups in the console in the documentation of `console` for more details.

Specifications
--------------

| Specification |
| --- |
| Console Standard # group |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `console.groupEnd()`
* `console.groupCollapsed()`
* Microsoft Edge's documentation for `console.group()`
* Node.JS documentation for `console.group()`
* Google Chrome's documentation for `console.group()`
console: profileEnd() static method
===================================

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The **`console.profileEnd()`** static method stops recording a profile previously started with `console.profile()`.

You can optionally supply an argument to name the profile. Doing so enables you to stop only that profile if you have multiple profiles being recorded.

* If `console.profileEnd()` is passed a profile name, and it matches the name of a profile being recorded, then that profile is stopped.
* If `console.profileEnd()` is passed a profile name and it does not match the name of a profile being recorded, no changes will be made.
* If `console.profileEnd()` is not passed a profile name, the most recently started profile is stopped.

**Note:** This feature is available in Web Workers

Syntax
------


```js
profileEnd(profileName)
```

### Parameters

`profileName` Optional

The name to give the profile.

### Return value

None (`undefined`).

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `console.profile()`
console: profile() static method
================================

**Non-standard:** This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The **`console.profile()`** static method starts recording a performance profile (for example, the Firefox performance tool).

You can optionally supply an argument to name the profile and this then enables you to stop only that profile if multiple profiles being recorded. See `console.profileEnd()` to see how this argument is interpreted.

To stop recording call `console.profileEnd()`.

**Note:** This feature is available in Web Workers

Syntax
------


```js
profile(profileName)
```

### Parameters

`profileName` Optional

The name to give the profile.

### Return value

None (`undefined`).

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `console.profileEnd()`
console: countReset() static method
===================================

The **`console.countReset()`** static method resets counter used with `console.count()`.

**Note:** This feature is available in Web Workers

Syntax
------


```js
countReset()
countReset(label)
```

### Parameters

`label` Optional

A string. If supplied, `countReset()` resets the count for that label to 0. If omitted, `countReset()` resets the default counter to 0.

### Return value

None (`undefined`).

Examples
--------

For example, given code like this:


```js
let user = "";

function greet() {
  console.count();
  return `hi ${user}`;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.count();
console.countReset();
```


Console output will look something like this:
```

"default: 1"
"default: 2"
"default: 3"
"default: 4"
"default: 0"
```


Note that the call to `console.counterReset()` resets the value of the default counter to zero.

If we pass the `user` variable as the `label` argument with the string "bob" to the first invocation of `console.count()`, and the string "alice" to the second:


```js
let user = "";

function greet() {
  console.count(user);
  return `hi ${user}`;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.countReset("bob");
console.count("alice");
```


We will see output like this:
```

"bob: 1"
"alice: 1"
"alice: 2"
"bob: 0"
"alice: 3"
```


Resetting the value of the counter "bob" only changes the value of that counter. The value of "alice" is unchanged.

Specifications
--------------

| Specification |
| --- |
| Console Standard # countreset |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.countReset()`
* Node.JS documentation for `console.countReset()`
* Google Chrome's documentation for `console.countReset()`
console: error() static method
==============================

The **`console.error()`** static method outputs an error message to the console.

**Note:** This feature is available in Web Workers

Syntax
------


```js
error(obj1)
error(obj1, /\* …, \*/ objN)
error(msg)
error(msg, subst1, /\* …, \*/ substN)
```

### Parameters

`obj1` … `objN`

A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output to the console.

`msg`

A JavaScript string containing zero or more substitution strings, which are replaced with `subst1` through `substN` in consecutive order.

`subst1` … `substN`

JavaScript objects with which to replace substitution strings within `msg`. This gives you additional control over the format of the output. See Using string substitutions for a description of how substitutions work.

See Outputting text to the console in the documentation of the `console` object for details.

### Return value

None (`undefined`).

Specifications
--------------

| Specification |
| --- |
| Console Standard # error |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.error()`
* Node.JS documentation for `console.error()`
* Google Chrome's documentation for `console.error()`
console: clear() static method
==============================

The **`console.clear()`** static method clears the console if the console allows it. A graphical console, like those running on browsers, will allow it; a console displaying on the terminal, like the one running on Node, will not support it, and will have no effect (and no error).

Syntax
------


```js
clear()
```

### Parameters

None.

### Return value

None (`undefined`).

Specifications
--------------

| Specification |
| --- |
| Console Standard # clear |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.clear()`
* Node.JS documentation for `console.clear()`
* Google Chrome's documentation for `console.clear()`
console: timeEnd() static method
================================

The **`console.timeEnd()`** static method stops a timer that was previously started by calling `console.time()`.

See Timers in the documentation for details and examples.

**Note:** This feature is available in Web Workers

Syntax
------


```js
timeEnd()
timeEnd(label)
```

### Parameters

`label` Optional

A string representing the name of the timer to stop. Once stopped, the elapsed time is automatically displayed in the console along with an indicator that the time has ended. If omitted, the label "default" is used.

### Return value

None (`undefined`).

Examples
--------


```js
console.time("answer time");
alert("Click to continue");
console.timeLog("answer time");
alert("Do a bunch of other stuff…");
console.timeEnd("answer time");
```


The output from the example above shows the time taken by the user to dismiss the first alert box, followed by the cumulative time it took for the user to dismiss both alerts:

![Timer output in Firefox console](/en-US/docs/Web/API/console/timeend_static/timer_output.png)

 Notice that the timer's name is displayed when the timer value is logged using `console.timeLog()` and again when it's stopped. In addition, the call to `console.timeEnd()` has the additional information, "timer ended" to make it obvious that the timer is no
 longer tracking time.

Specifications
--------------

| Specification |
| --- |
| Console Standard # timeend |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* `console.time()`
* `console.timeLog()`
* Microsoft Edge's documentation for `console.timeEnd()`
* Node.JS documentation for `console.timeEnd()`
* Google Chrome's documentation for `console.timeEnd()`
console: debug() static method
==============================

The **`console.debug()`** static method outputs a message to the console at the "debug" log level. The message is only displayed to the user if the console is configured to display debug output. In most cases, the log level is configured within the console UI. This log level might correspond to the `Debug` or `Verbose` log level.

**Note:** This feature is available in Web Workers

Syntax
------


```js
debug(obj1)
debug(obj1, /\* …, \*/ objN)
debug(msg)
debug(msg, subst1, /\* …, \*/ substN)
```

### Parameters

`obj1` … `objN`

A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and output to the console.

`msg`

A JavaScript string containing zero or more substitution strings, which are replaced with `subst1` through `substN` in consecutive order.

`subst1` … `substN`

JavaScript objects with which to replace substitution strings within `msg`. This gives you additional control over the format of the output. See Using string substitutions for a description of how substitutions work.

See Outputting text to the console in the documentation of the `console` object for details.

### Return value

None (`undefined`).

Specifications
--------------

| Specification |
| --- |
| Console Standard # debug |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.debug()`
* Node.JS documentation for `console.debug()`
* Google Chrome's documentation for `console.debug()`
console: trace() static method
==============================

The **`console.trace()`** static method outputs a stack trace to the console.

**Note:** This feature is available in Web Workers

**Note:** In some browsers, `console.trace()` may also output the sequence of calls and asynchronous events leading to the current `console.trace()` which are not on the call stack — to help identify the origin of the current event evaluation loop.

See Stack traces in the `console` documentation for details and examples.

Syntax
------


```js
trace()
trace(object1, /\* …, \*/ objectN)
```

### Parameters

`objects` Optional

Zero or more objects to be output to console along with the trace. These are assembled and formatted the same way they would be if passed to the `console.log()` method.

### Return value

None (`undefined`).

Examples
--------


```js
function foo() {
  function bar() {
    console.trace();
  }
  bar();
}

foo();
```


In the console, the following trace will be displayed:
```

bar
foo
<anonymous>
```

Specifications
--------------

| Specification |
| --- |
| Console Standard # trace |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.trace()`
* Node.JS documentation for `console.trace()`
* Google Chrome's documentation for `console.trace()`
console: assert() static method
===============================

The **`console.assert()`** static method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

**Note:** This feature is available in Web Workers

Syntax
------


```js
assert(assertion)

assert(assertion, obj1)
assert(assertion, obj1, obj2)
assert(assertion, obj1, obj2, /\* …, \*/ objN)

assert(assertion, msg)
assert(assertion, msg, subst1)
assert(assertion, msg, subst1, /\* …, \*/ substN)
```

### Parameters

`assertion`

Any boolean expression. If the assertion is false, a generic message indicating assertion failure is written to the console.

`obj1` … `objN`

A list of JavaScript objects to output. A representation of each of these objects is output to the console after a generic assertion failure message (which may be different from the message output when these objects are not present) in the order given with some type of separation between the message and between each of them. There is a special case if `obj1` is a string, which is described subsequently.

`msg`

A JavaScript string containing zero or more substitution strings, which are replaced with `subst1` through `substN` in consecutive order up to the number of substitution strings. A colon, a space, and then the substituted string are appended to the generic assertion message to form a detailed assertion message, and the result is output to the console.

`subst1` … `substN`

JavaScript objects with which to replace substitution strings within `msg`. This gives you additional control over the format of the output. See Using string substitutions for a description of how substitutions work. If there are more substutition objects than there are substitution strings, the extra objects are themselves written to the console after the detailed assertion message in the same manner as described for objects written after a generic assertion message.

### Return value

None (`undefined`).

Examples
--------

The following code example demonstrates the use of a JavaScript object following the assertion:


```js
const errorMsg = "the # is not even";
for (let number = 2; number <= 5; number++) {
  console.log(`the # is ${number}`);
  console.assert(number % 2 === 0, "%o", { number, errorMsg });
}
// output:
// the # is 2
// the # is 3
// Assertion failed: {number: 3, errorMsg: "the # is not even"}
// the # is 4
// the # is 5
// Assertion failed: {number: 5, errorMsg: "the # is not even"}
```


See Using string substitutions in the documentation of `console` for further details.

Specifications
--------------

| Specification |
| --- |
| Console Standard # assert |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.assert()`
* Node.JS documentation for `console.assert()`
* Google Chrome's documentation for `console.dir()`
console: count() static method
==============================

The **`console.count()`** static method logs the number of times that this particular call to `count()` has been called.

**Note:** This feature is available in Web Workers

Syntax
------


```js
count()
count(label)
```

### Parameters

`label` Optional

A string. If supplied, `count()` outputs the number of times it has been called with that label. If omitted, `count()` behaves as though it was called with the "default" label.

### Return value

None (`undefined`).

Examples
--------

For example, given code like this:


```js
let user = "";

function greet() {
  console.count();
  return `hi ${user}`;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.count();
```


Console output will look something like this:
```

"default: 1"
"default: 2"
"default: 3"
"default: 4"
```


The label is displayed as `default` because no explicit label was supplied.

If we pass the `user` variable as the `label` argument to the first invocation of `console.count()`, and the string "alice" to the second:


```js
let user = "";

function greet() {
  console.count(user);
  return `hi ${user}`;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.count("alice");
```


We will see output like this:
```

"bob: 1"
"alice: 1"
"alice: 2"
"alice: 3"
```


We're now maintaining separate counts based only on the value of `label`.

Specifications
--------------

| Specification |
| --- |
| Console Standard # count |

Browser compatibility
---------------------

BCD tables only load in the browser with JavaScript enabled. Enable JavaScript to view data.

See also
--------

* Microsoft Edge's documentation for `console.count()`
* Node.JS documentation for `console.count()`
* Google Chrome's documentation for `console.count()`