Console API
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
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
BCD tables only load in the browser
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