|
Chrome |
Firebug |
Firefox |
IE |
Node.js |
Safari |
Opera |
- assert(expression[, object, ...])
- If false, it displays console.error, else nothing.
|
|
+ |
+ |
+ (28+) |
+ |
+ |
+ |
± |
- clear()
- Clears console window.
|
|
+ |
+ |
-⊝- |
+ |
-⊝- |
+ |
+ |
- count([object])
- It displays the number of passes of a given point code every time. If there is an argument object, it is displayed object.toString() before the counter.
|
|
+ |
+ |
+ (30+) |
+ |
-⊝- |
+ |
± ... |
- debug(object[, object, ...])
- The equivalent of console.log for compatibility with the old version of the object console, where .debug shows additonal link on the line of code, from which method was called.
|
equals .log() |
+ |
+ |
+ |
+ |
-⊝- |
+ |
± ... |
- dir(object)
- object it appears as a Javascript-object (for DOM-elements shows all of its attributes and methods). %O works in console.log in Chrome similarly.
|
|
+ |
+ |
+ (8+) |
+ (9+) |
+ |
+ |
+ |
- dirxml(object)
- Outputs XML code of object.
|
|
+ |
+ |
-⊝- |
+ (11+) |
-⊝- |
+ |
± ... |
- error(object[, object, ...])
- Sends an error message to the console and console.trace for the position from which it was called (without stopping the execution of the program). Patterns are supports (%s, %d (%i), %f, %o, %O, %c), as in console.log. Example of tracing the call stack (Firefox 31+):
![](https://raw.githubusercontent.com/spmbt/jsConsoleApiReference/gh-pages/img/console-stack-traces.png)
|
|
+ |
± ... |
+ |
+ (8+) |
+ |
+ |
± ... |
- exception(object[, object, ...])
- Equals to .error().
|
equal .error() |
-⊝- |
-⊝- |
+ (28+) |
-⊝- |
-⊝- |
-⊝- |
-⊝- |
- group(object[, object, ...])
- Starts Expanded group logs in the console, which can then be roll up manually. Group terminates the command .groupEnd (). Patterns are supported (see .log()). Sample code and output (from the article «Browser console opportunities (ru)», 2013):
(javascript)
console.group("module A")
console.log('a')
console.log('a')
console.log('a')
console.group("nested module B")
console.log('b')
console.log('b')
console.log('b')
console.groupEnd()
console.groupCollapsed("nested collapsed module C")
console.log('c')
console.log('c')
console.log('c')
console.groupEnd()
console.groupEnd()
console.group("module D")
console.log('d')
console.log('d')
console.log('d')
console.groupEnd()
<img src="img/groupLog.png"/></dd></dl></td>
|
|
+ |
+ |
± ... |
+ (11+) |
-⊝- |
+ (4+) |
+ |
- groupCollapsed(object[, object, ...])
- Starts collapsed group of log in the console, which can then unfold manually. Group terminates by command .groupEnd(). Patterns are supported (see .log()).
|
|
+ |
+ |
± ... (9+) |
+ (11+) |
-⊝- |
+ (5.1+) |
+ |
- groupEnd()
- Indicates the end of the group of log messages that can fold or unfold (except Firefox) manually.
|
|
+ |
+ |
+ (9+) |
+ (11+) |
-⊝- |
+ (4+) |
+ |
|
Chrome |
Firebug |
Firefox |
IE |
Node.js |
Safari |
Opera |
- info(object[, object, ...])
- The operation is similar to the .log(), but is made in a different design to distinguish the types of messages, for example, the importance of graduation or for other semantic meaning of this group of messages. Patterns are supported (described in .log()). An example of differences for Firebug, Chrome, IE9:
![](https://raw.githubusercontent.com/spmbt/jsConsoleApiReference/gh-pages/img/consoleMessages.png)
|
|
+ |
+ |
+ |
+ |
+ |
+ |
+ |
- log(object[, object, ...])
- Displays the arguments in the console, separated by spaces. The most popular command in console.
It supports patterns, which are special names in the first argument, indicating that it should be to use as template, in which following arguments will be substituted instead variables of pattern (as in printf() in C, but it is much easier). Examples:
(javascript)
console.log('Peter had %d %s', 10,'apples');
console.log('Pi is equal to %f', Math.PI);
console.log('%cRichard %cOf %cYork%c Gave Battle In Vain','color:red;',
'font-size:16px;color:orange;','background:black;color:yellow;',
'font:normal;color:normal;background:normal;');
console.log('body as DOM: %o',document.getElementsByTagName('body')[0]);
console.log('object: %O',{a:1,b:2});
console.log('body as Object: %O',document.getElementsByTagName('body')[0]);
Types of patterns and data type to which it converts values:<br>
<b>%s</b> — string.<br>
<b>%d</b> or <b>%i</b> — number.<br>
<b>%f</b> — float number (Firebug supports also).<br>
<b>%o</b> — DOM-element (Firebug outputs as reference to element. Chrome, in addition to references, displays an item in the console. Firefox opens in a modal window by click (all attributes and methods of this object are available)).<br>
<b>%O</b> — JS object (not supported in Firefox; Chrome converts DOM object to JS object for this pattern; Firebug does not distinguish <b>%o</b> and <b>%O</b>).<br>
<b>%c</b> — CSS-style (color, background, font; in Firefox is supported from version 31). Example of stylization by pattern <b>%c</b> (Firefox):<br>
<img src="img/styled-console-logs.png"/></dd></dl></td>
|
(important) |
+ |
+ |
+ |
+ |
+ |
+ |
± ... |
- markTimeline()
- Synonym of .timeStamp() for Safari, but .timeStamp() is not supported in it, and vice versa.
|
=.timeStamp() |
-⊝- |
-⊝- |
-⊝- |
-⊝- |
-⊝- |
+ |
-⊝- |
- profile([label])
- Starts Javascript-profiler, then shows results under name label.
|
|
+ |
+ |
(devtools) |
+ (10+) |
-⊝- |
+ |
-⊝- |
- profileEnd()
- Turns off Javascript-profiler.
|
|
+ |
+ |
(devtools) |
+ (10+) |
-⊝- |
+ |
-⊝- |
- table(data[, columns])
- The two-dimensional tabular data presented in a tabular format. Data is array or object (or object of objects, object of arrays), each element of which is a string in the table. The first column of a two-dimensional array will be its index (from 0). Or, if there is an object, the first column would consist of keys of the object. Example in Firefox (object of objects):
![](https://raw.githubusercontent.com/spmbt/jsConsoleApiReference/gh-pages/img/tableLog.png)
Columns is optional array of names of columns for the table header, if the strings are built from arrays, and we do not want to have the names of numeric codes. Above was an example of the result (Firefox), either obtained from the named column or object of objects. Below we show that it would be from an array of arrays without parameter columns:
![](https://raw.githubusercontent.com/spmbt/jsConsoleApiReference/gh-pages/img/tableLogNoHeader.png)
|
|
+ |
+ |
+ (34+) |
-⊝- |
-⊝- |
-⊝- |
-⊝- |
- time(label)
- Turns on milliseconds counter with name label.
|
|
+ |
+ |
+ (10+) |
+ (11+) |
+ |
+ (4+) |
± |
- timeEnd(label)
- Stops milliseconds counter with name label and outputs result. Example (Chrome):
![](https://raw.githubusercontent.com/spmbt/jsConsoleApiReference/gh-pages/img/time-duration.png)
|
|
+ |
+ |
+ (10+) |
+ (11+) |
+ |
+ (4+) |
± |
- timeStamp([label])
- Draws the timestamp on the chart timings script for monitor the dynamics of the behavior of the program. Example (Firebug):
![](https://raw.githubusercontent.com/spmbt/jsConsoleApiReference/gh-pages/img/timestampLog.png)
|
|
+ |
+ |
-⊝- |
-⊝- |
-⊝- |
-⊝- |
-⊝- |
- trace()
- Shows the stack trace of function at the moment of execution (the same that is normally displayed when you stop on the error points). The example in Safari (in sidebar), in Chrome (console):
![](https://raw.githubusercontent.com/spmbt/jsConsoleApiReference/gh-pages/img/stackTraceConsoleChrome.png)
In Firefox:
![](https://raw.githubusercontent.com/spmbt/jsConsoleApiReference/gh-pages/img/stackTraceConsoleFirefox.png)
|
|
+ |
+ |
+ (10+) |
+ (11+) |
+ |
+ (7.01+) |
± ... |
- warn(object[, object, ...])
- Similar to .log() and .info(), but drawn in different design to distinguish the types of messages. Patterns are supported (described in .log()).
|
|
+ |
+ |
+ |
+ |
+ |
+ |
+ |
- debugger;
- This operator stops Javascript on the current line. It is equal to a breakpoint in the debug panel. Does not affect the running program except stopping.
|
(operator) |
+ |
+ |
+ |
+ |
+ |
+ |
+ |
- throw new Error('mesasge');
- It stops Javascript on the current line, interrupting the execution. (This operator is supported by all execution environments of Javascript.)
|
|
|
|
|
|
|
|
|