Reference of methods for the console object in various browsers and Javascript environments

  • Github jsConsoleApiReference of this (please visit to repo and contribute new data); (latest update: 2015-03-21).
  • Chrome
    Firebug
    Firefox
     IE
    Node.js
    Safari
    Opera
    assert(expression[, object, ...])
    If false, it displays console.error, else nothing.
      +   +   + (28.0+)   +   +   +   ±
    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.0+)   + -⊝-   + ± ...
    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+):
      + ± ...   +   + (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()
    

      +   + ± ...   + (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:
      +   +   +   +   +   +   +
    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:
    %s — string.
    %d or %i — number.
    %f — float number (Firebug supports also).
    %o — 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)).
    %O — JS object (not supported in Firefox; Chrome converts DOM object to JS object for this pattern; Firebug does not distinguish %o and %O).
    %c — CSS-style (color, background, font; in Firefox is supported from version 31). Example of stylization by pattern %c (Firefox):
       (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):

    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:
      +   +   + (34.0+) -⊝- -⊝- -⊝- -⊝-
    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):
      +   +   + (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):
      +   + -⊝- -⊝- -⊝- -⊝- -⊝-
    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):

    In Firefox:
      +   +   + (10+) + (11+)   + + (7.0.1+) ± ...
    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.)

    References and explorations of console

    This page can be displayed in multiple views. If you open it


    © 2015, spmbt