Name

Console — debugging output

Synopsis

Modern browsers (and older ones with debugger extensions, such as Firebug, installed) define a global property console that refers to a Console object. The methods of this object define a API for simple debugging tasks, such as logging messages to a console window (the console may go by a name such as “Developer Tools” or “Web Inspector”).

There is no formal standard that defines the Console API, but the Firebug debugger extension for Firefox has established a de facto standard and browser vendors seem to be implementing the Firebug API, which is documented here. Support for the basic console.log() function is nearly universal, but the other functions may not be as well supported in all browsers.

Note that in some older browsers, the console property is only defined when the console window is open, and running scripts that use the Console API without the console open will cause errors.

See also ConsoleCommandLine.

Methods

void assert(any expression, string message)

Display an error message on the console if expression is false or a falsy value like null, undefined, 0, or the empty string.

void count([string title])

Display the specified title string along with a count of the number of times that this method has been called with that string.

void debug(any message...)

Like console.log(), but mark the output as debugging information.

void dir(any object)

Display the JavaScript object on the console in a way that allows the developer to examine its properties ...

Get JavaScript: The Definitive Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.