Console API

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Note: This feature is available in Web Workers.

The Console API provides functionality to allow developers to perform debugging tasks, such as logging messages or the values of variables at set points in your code, or timing how long an operation takes to complete.

Concepts and usage

The Console API started as a largely proprietary API, with different browsers implementing it, albeit in inconsistent ways. The Console API spec was created to define consistent behavior, and all modern browsers eventually settled on implementing this behavior — although some implementations still have their own additional proprietary functions. Find out about these at:

Usage is very simple — the console object contains many methods that you can call to perform rudimentary debugging tasks, generally focused around logging various values to the browser's Web Console.

By far the most commonly-used method is console.log(), which is used to log the current value contained inside a specific variable.

Interfaces

console

Provides rudimentary debugging functionality, including logging, stack traces, timers, and counters.

Examples

js
let myString = "Hello world";

// Output "Hello world" to the console
console.log(myString);

See the console reference page for more examples.

Specifications

Specification
Console Standard
# console-namespace

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
console
assert() static method
clear() static method
countReset() static method
count() static method
debug() static method
dir() static method
options.colors parameter
ExperimentalNon-standard
options.depth parameter
ExperimentalNon-standard
options.showHidden parameter
ExperimentalNon-standard
dirxml() static method
error() static method
exception() static method (an alias for error())
DeprecatedNon-standard
groupCollapsed() static method
groupEnd() static method
group() static method
info() static method
log() static method
profileEnd() static method
Non-standard
profile() static method
Non-standard
Substitution strings
table() static method
timeEnd() static method
timeLog() static method
timeStamp() static method
Non-standard
time() static method
trace() static method
warn() static method
Available in workers

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
Non-standard. Check cross-browser support before using.
Deprecated. Not for use in new websites.
See implementation notes.
User must explicitly enable this feature.
Has more compatibility info.

See also

  • Tools
  • Web Console — how the Web Console in Firefox handles console API calls
  • about:debugging — how to see console output when the debugging target is a mobile device