Can’t make the #ChromeDevSummit this year? Catch all the content (and more!) on the livestream, or join your peers for a CDS Extended event at a hosted location nearby. To learn more, check out the Chrome Dev Summit 2019 website.

Console API Reference

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.
Figure 1. The result of the console.assert() example above.

console.clear()

Clears the console.

console.clear();

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

See also: Clear the Console

console.count([label])

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.

console.count();
console.count('coffee');
console.count();
console.count();
The result of the console.count() example above.
Figure 2. The result of the console.count() example above.

console.countReset([label])

Resets a count.

console.countReset();
console.countReset('coffee');

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

Log level: Info

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

console.debug('debug');
The result of the console.debug() example above.
Figure 3. The result of the console.debug() example above.

console.dir(object)

Log level: Info

Prints a JSON representation of the specified object.

console.dir(document.head);
The result of the console.dir() example above.
Figure 4. The result of the console.dir() example above.

console.dirxml(node)

Log level: Info

Prints an XML representation of the descendants of node.

console.dirxml(document);
The result of the console.dirxml() example above.
Figure 5. 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.
Figure 6. The result of the console.error() example above.

console.group(label)

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';
console.group(label);
console.info('Leo');
console.info('Mike');
console.info('Don');
console.info('Raph');
console.groupEnd(label);
The result of the console.group() example above.
Figure 7. The result of the console.group() example above.

console.groupCollapsed(label)

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

console.groupEnd(label)

Stops visually grouping messages. See console.group.

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

Log level: Info

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

console.info('info');
The result of the console.info() example above.
Figure 8. The result of the console.info() example above.

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

Log level: Info

Prints a message to the Console.

console.log('log');
The result of the console.log() example above.
Figure 9. The result of the console.log() example above.

console.table(array)

Log level: Info

Logs an array of objects as a table.

console.table([
  {
    first: 'René',
    last: 'Magritte',
  },
  {
    first: 'Chaim',
    last: 'Soutine',
    birthday: '18930113',
  },
  {
    first: 'Henri',
    last: 'Matisse',
  }
]);
The result of the console.table() example above.
Figure 10. The result of the console.table() example above.

console.time([label])

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

console.time();
for (var i = 0; i < 100000; i++) {
  let square = i ** 2;
}
console.timeEnd();
The result of the console.time() example above.
Figure 11. The result of the console.time() example above.

console.timeEnd([label])

Log level: Info

Stops a timer. See console.time().

console.trace()

Log level: Info

Prints a stack trace to the Console.

const first = () => { second(); };
const second = () => { third(); };
const third = () => { fourth(); };
const fourth = () => { console.trace(); };
first();
The result of the console.trace() example above.
Figure 12. The result of the console.trace() example above.

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

Log level: Warning

Prints a warning to the Console.

console.warn('warn');
The result of the console.warn() example above.
Figure 13. The result of the console.warn() example above.

Feedback

Was this page helpful?
Yes
What was the best thing about this page?
It helped me complete my goal(s)
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It had the information I needed
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It had accurate information
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It was easy to read
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
Something else
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
No
What was the worst thing about this page?
It didn't help me complete my goal(s)
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It was missing information I needed
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It had inaccurate information
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
It was hard to read
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.
Something else
Thank you for the feedback. If you have specific ideas on how to improve this page, please create an issue.