Chrome Dev Summit 2018 is happening now and streaming live on YouTube. Watch now.

Console API Reference

Use the Console API to write information to the console, create JavaScript profiles, and start a debugging session.

console.assert(expression, object)

Writes an error to the console when the evaluated expression is false.

function greaterThan(a,b) {
  console.assert(a > b, {"message":"a is not greater than b","a":a,"b":b});

console.assert() example


Clears the console.


If the Preserve log checkbox is enabled, console.clear() is disabled. However, pressing the clear console button (clear console button) or typing the shortcut Ctrl+L while the Console is in focus still works.

See Clearing the console for more information.


Writes the number of times that count() has been invoked at the same line and with the same label.

function login(name) {
  console.count(name + ' logged in');

console.count() example

See Counting Statement Executions for more examples.

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

Identical to console.log().


Prints a JavaScript representation of the specified object. If the object being logged is an HTML element, then the properties of its DOM representation are printed, as shown below:


klzzwxh:0018 example

Learn about the functionally equivalent object formatter (%O) and more in String substitution and formatting.


Prints an XML representation of the descendant elements of object if possible, or the JavaScript representation if not. Calling console.dirxml() on HTML and XML elements is equivalent to calling console.log().


console.dirxml() example

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

Prints a message similar to console.log(), styles the message like an error, and includes a stack trace from where the method was called.

console.error('error: name is undefined');

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

Starts a new logging group with an optional title. All console output that occurs after and before console.groupEnd() is visually grouped together.

function name(obj) {'name');
  console.log('first: ', obj.first);
  console.log('middle: ', obj.middle);
  console.log('last: ', obj.last);

name({"first":"Wile","middle":"E","last":"Coyote"}); example

You can also nest groups:

function name(obj) {'name');
  console.log('first: ', obj.first);
  console.log('middle: ', obj.middle);
  console.log('last: ', obj.last);

function doStuff() {'doStuff()');


nested example

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

Creates a new logging group that is initially collapsed instead of open.

console.log("peekaboo, you can't see me");


Closes a logging group. See for an example. [, object, ...])

Prints a message like console.log() but also shows an icon (blue circle with white "i") next to the output.

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

Displays a message in the console. Pass one or more objects to this method. Each object is evaluated and concatenated into a space-delimited string.

console.log('Hello, Logs!');

Format specifiers

The first object you pass can contain one or more format specifiers. A format specifier is composed of the percent sign (%) followed by a letter that indicates the formatting to apply.

Related Guides:


Starts a JavaScript CPU profile with an optional label. To complete the profile, call console.profileEnd(). Each profile is added to the Profiles panel.

function processPixels() {
  // later, after processing pixels


Stops the current JavaScript CPU profiling session if one is in progress and prints the report to the Profiles panel.

See console.profile() for an example.


Logs an array of objects as a table.

let data = [
  { name: "Yusuf", age: 26 },
  { age: 34, name: "Chen" }


an example of console.table()


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

var arr = new Array(10000);
for (var i = 0; i < arr.length; i++) {
  arr[i] = new Object();
// default: 3.696044921875ms

Pass an optional label to change the output text that precedes the elapsed time. Call console.timeEnd() with the same label to stop the timer.

var arr = new Array(10000);
for (var i = 0; i < arr.length; i++) {
  arr[i] = new Object();
// total: 3.696044921875ms

Use labels to run multiple timers at the same time.

console.time('init arr');
var arr = new Array(10000);
console.timeEnd('init arr');
for (var i = 0; i < arr.length; i++) {
  arr[i] = new Object();
// init arr: 0.0546875ms
// total: 2.5419921875ms


Stops a timer. See console.time() for examples.


Adds an event to the Timeline during a recording session.

console.timeStamp('check out this custom timestamp thanks to console.timeStamp()!');

console.timeStamp() example

Related Guides:


Prints a stack trace from the point where the method was called.


console.trace() example

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

Prints a message like console.log(), but also displays a yellow warning icon next to the logged message.

console.warn('user limit reached!');

console.warn() example


Was this page helpful?