Console API reference

Sofia Emelianova
Sofia Emelianova

Use the Console API to write messages to the Console from your JavaScript. See Get started with logging messages to the Console for an interactive introduction to the topic.

See Console utilities API reference if you're looking for the convenience methods like debug(function) or monitorEvents(node) which are only available from the Console.

console.assert(expression, object)

Log level: Error

Writes an error to the console when expression evaluates to false.

const x = 5;
const y = 3;
const reason = 'x is expected to be less than y';
console.assert(x < y, {x, y, reason});

The result of the console.assert() example above.


Clears the console.


If Preserve Log is enabled, console.clear() is disabled.

Alternatively, you can Clear the Console by clicking the ALT_TEXT_HERE icon.


Log level: Info

Writes the number of times that count() has been invoked at the same line and with the same label. Call console.countReset([label]) to reset the count.


The result of the console.count() example above.


Resets a count.



Returns a Task instance that associates the current stack trace with the created task object. You can later use this task object to run a function (f in the following example). The executes an arbitrary payload and forwards the return value back to the caller.

// Task creation
const task = console.createTask(name);

// Task execution; // instead of f();

The task forms a link between the creation context and the context of the async function. This link lets DevTools show better stack traces for async operations. For more information, see Linked Stack Traces.

console.debug(object [, object, ...])

Log level: Verbose

Identical to console.log(object [, object, ...]) except different log level.


The result of the console.debug() example above.


Log level: Info

Prints a JSON representation of the specified object.


The result of the console.dir() example above.


Log level: Info

Prints an XML representation of the descendants of node.


The result of the console.dirxml() example above.

console.error(object [, object, ...])

Log level: Error

Prints object to the Console, formats it as an error, and includes a stack trace.

console.error("I'm sorry, Dave. I'm afraid I can't do that.");

The result of the console.error() example above.

Visually groups messages together until console.groupEnd(label) is called. Use console.groupCollapsed(label) to collapse the group when it's initially logged to the Console.

const label = 'Adolescent Irradiated Espionage Tortoises';;'Leo');'Mike');'Don');'Raph');

The result of the example above.

Additionally, you can nest groups.

const timeline1 = 'New York 2012';
const timeline2 = 'Camp Lehigh 1970';;'Mind');'Time');;'Space');'Extra Pym Particles');

Nested groups.


Same as, except the group is initially collapsed when it's logged to the Console.


Stops visually grouping messages. See [, object, ...])

Log level: Info

Identical to console.log(object [, object, ...]).'info');

The result of the example above.

console.log(object [, object, ...])

Log level: Info

Prints a message to the Console.


The result of the console.log() example above.

console.table(array [, columns])

Log level: Info

Logs an array of objects as a table.

var people = [
    first: 'René',
    last: 'Magritte',
    first: 'Chaim',
    last: 'Soutine',
    birthday: '18930113',
    first: 'Henri',
    last: 'Matisse',

The result of the console.table() example above.

By default, console.table() logs all table data. To display a single column or a subset of columns, you can use the second optional parameter and specify column name or names as a string or an array of strings. For example:

console.table(people, ['last', 'birthday']);

A subset of columns in a table logged with console.table().


Starts a new timer. Call console.timeEnd([label]) to stop the timer and print the elapsed time to the Console.

for (var i = 0; i < 100000; i++) {
  let square = i ** 2;

The result of the console.time() example above.


Log level: Info

Stops a timer. See console.time().


Log level: Info

Prints a stack trace to the Console.

const first = () => { second(); };
const second = () => { third(); };
const third = () => { fourth(); };
const fourth = () => { console.trace(); };

The result of the console.trace() example above.

console.warn(object [, object, ...])

Log level: Warning

Prints a warning to the Console.


The result of the console.warn() example above.