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 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.


Starts a new timer with an associated label. When console.timeEnd() is called with the same label, the timer is stopped and the elapsed time is displayed in the console. Timer values are accurate to the sub-millisecond. The strings passed to time() and timeEnd() must match or else the timer will not finish.

console.time("Array initialize");
var array = new Array(1000000);
for (var i = array.length - 1; i >= 0; i--) {
  array[i] = new Object();
console.timeEnd("Array initialize");

console.time() example


Stops the current timer if one is in progress and prints the timer label followed by the elapsed time to the Console.

See console.time() for an example.


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