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";
console.log(myString);
See the console reference page for more examples.
Specifications
Browser compatibility
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
Console_API |
1 |
12 |
4 |
8In Internet Explorer 8 and 9, the console object is undefined when the developer tools are not open. This behavior was fixed in Internet Explorer 10. |
10.5 |
3 |
≤37 |
18 |
4 |
11 |
1 |
1.0 |
assert |
2 |
12 |
28 |
8 |
11 |
4 |
≤37 |
18 |
28 |
11 |
3.2 |
1.0 |
clear |
25 |
12 |
39 |
8 |
12 |
7 |
4.4 |
25 |
39 |
12 |
7 |
1.5 |
count |
2 |
12 |
30 |
11 |
11 |
4 |
≤37 |
18 |
30 |
11 |
3.2 |
1.0 |
countReset |
68 |
79 |
62 |
No |
55 |
13 |
68 |
68 |
62 |
48 |
13 |
10.0 |
debug |
2 |
12 |
5 |
10 |
11 |
4 |
≤37 |
18 |
5 |
11 |
3.2 |
1.0 |
dir |
2 |
12 |
8 |
9 |
11 |
4 |
≤37 |
18 |
8 |
11 |
3.2 |
1.0 |
dirxml |
2 |
12 |
39 |
11 |
11 |
4 |
≤37 |
18 |
39 |
11 |
3.2 |
1.0 |
error |
1 |
12 |
4 |
8 |
10.5 |
3 |
4.4 |
18 |
4 |
11 |
1 |
1.0 |
exception |
No |
13–79 |
28 |
No |
No |
No |
No |
No |
28 |
No |
No |
No |
group |
2 |
12 |
9 |
11 |
11 |
4 |
37 |
18 |
9 |
11 |
3.2 |
1.0 |
groupCollapsed |
6 |
12 |
9 |
11 |
11 |
5.1 |
3 |
18 |
9 |
11 |
5 |
1.0 |
groupEnd |
2 |
12 |
9 |
11 |
11 |
4 |
37 |
18 |
9 |
11 |
3.2 |
1.0 |
info |
1 |
12 |
4 |
8 |
10.5 |
3 |
4.4 |
18 |
4 |
11 |
1 |
1.0 |
log |
1 |
12 |
4 |
8 |
10.5 |
3 |
4.4 |
18 |
4 |
11 |
1 |
1.0 |
profile |
5 |
12 |
16–102 |
9 |
11 |
4 |
≤37 |
18 |
16–102 |
11 |
3.2 |
1.0 |
profileEnd |
5 |
12 |
16 |
9 |
11 |
4 |
≤37 |
18 |
16 |
11 |
3.2 |
1.0 |
substitution_strings |
1In version 28, if a negative value is passed to %d, it will be rounded down to the closest negative integer, so -0.1 becomes -1. |
12["Before Edge 79, %c is not supported.", "Before Edge 79, %d outputs a 0 if the specified value isn't a number."] |
9 |
10["%c is not supported.", "%d outputs a 0 if the specified value isn't a number."] |
15 |
3 |
≤37In version 28, if a negative value is passed to %d, it will be rounded down to the closest negative integer, so -0.1 becomes -1. |
18In version 28, if a negative value is passed to %d, it will be rounded down to the closest negative integer, so -0.1 becomes -1. |
9 |
14 |
1 |
1.0In Samsung Internet 1.5, if a negative value is passed to %d, it will be rounded down to the closest negative integer, so -0.1 becomes -1. |
table |
27 |
13 |
34 |
No |
11 |
7 |
4.4 |
27 |
34 |
11 |
7 |
1.5 |
time |
2 |
12 |
10 |
11 |
11 |
4 |
≤37 |
18 |
10 |
11 |
3.2 |
1.0 |
timeEnd |
2 |
12 |
10 |
11 |
11 |
4 |
≤37 |
18 |
10 |
11 |
3.2 |
1.0 |
timeLog |
71 |
79 |
62 |
No |
60 |
13 |
71 |
71 |
62 |
50 |
13 |
10.0 |
timeStamp |
15 |
12 |
39 |
11 |
15 |
6 |
≤37 |
18 |
39 |
14 |
6 |
1.0 |
trace |
2 |
12 |
6 |
11 |
11 |
4 |
≤37 |
18 |
6 |
11 |
3.2 |
1.0 |
warn |
1 |
12 |
4 |
8 |
10.5 |
3 |
4.4 |
18 |
4 |
11 |
1 |
1.0 |
worker_support |
31 |
12 |
29 |
10 |
≤12.1 |
7 |
4.4.3 |
31 |
29 |
≤12.1 |
7 |
2.0 |
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