HTML CSS Bootstrap Javascript Icons Python
JavaScript Reference
Overview
JS Reference
JS Array Object JS Boolean Object JS Date Object JS Style Declaration Object JS Error Object JS Global Object JS Math Object JS Number Object JS String Object JS RegExp Object JS Statements
DOM Reference
DOM Attribute DOM Console DOM Document DOM Element DOM Events DOM Event Objects DOM History DOM HTMLCollection DOM Location DOM Navigator DOM Screen DOM Style DOM Window WEB Storage

JavaScript Console Object

The Console Object

The Console object provides access to the browser's debugging console.

The most frequently-used feature of the console is logging of text and other data.

The simplest way to use the logging methods is to output a string:

Run code

You can also output multiple objects by simply listing them when calling the logging method, like this:

Run code

Use the %c directive to apply a CSS style to console output:

Run code

The text before the directive will not be affected, but the text after the directive will be styled using the CSS declarations in the parameter.

This code demonstrates how to use multiple %c directives to apply CSS styles to console output:

Run code

Console Object Methods

The following table lists the methods of the Console object:

Method Description
assert() Log a message and stack trace to console if the first argument is false
clear() Clears the console
count() Logs the number of times that this particular call to count() has been called
error() Outputs an error message to the console
group() Creates a new inline group, indenting all following output by another level. To move back out a level, call groupEnd()
groupCollapsed() Creates a new inline group in the console. However, the new group is created collapsed. The user will need to use the disclosure button to expand it
groupEnd() Exits the current inline group
info() Outputs an informational message to the console
log() Outputs a message to the console
table() Displays tabular data as a table
time() Starts a timer (can track how long an operation takes)
timeEnd() Stops a timer that was previously started by console.time()
trace() Outputs a stack trace to the console
warn() Outputs a warning message to the console