Cool Console Commands

console.assert()

console.assert()

Writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

console.assert(document.querySelector('root'), 'No root!')

console.count()

Logs the number of times that this particular call to count() has been called. This function takes an optional argument label.

for (i = 0; i < 10; i++) { console.count('Count'); }

console.clear()

Clears the console.

>

console.dir()

Displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.

var event = { name: 'San Diego JS' }; console.dir(event);

console.error()

Outputs an error message to the Web Console.

console.error('help');

console.group()

Creates a new inline group in the Web Console log. This indents following console messages by an additional level, until console.groupEnd() is called.

console.log("Updating user information"); console.group('All Users:'); console.log("Looking for user...."); console.group('User #941039'); console.log("Saving user...."); console.error("Couldn't save user!"); console.groupEnd(); console.groupEnd();

console.groupCollapsed()

Creates a new inline group in the Web Console. Unlike console.group(), however, the new group is created collapsed. The user will need to use the disclosure button next to it to expand it, revealing the entries created in the group.

console.log("Updating user information"); console.groupCollapsed('All Users:'); console.log("Looking for user...."); console.groupCollapsed('User #941039'); console.log("Saving user...."); console.error("Couldn't save user!"); console.groupEnd(); console.groupEnd();

console.groupEnd()

Exits the current inline group in the Web Console.

console.groupEnd()

console.info()

Outputs an informational message to the Web Console. In Firefox and Chrome, a small "i" icon is displayed next to these items in the Web Console's log.

console.info('Ok, about to do stuff')

console.log()

Outputs a message to the Web Console.

console.log('You should know what this is')

console.table()

Displays tabular data as a table. This function takes one mandatory argument data, which must be an array or an object, and one additional optional parameter columns.

var famousRappers = { 'jayz' : { firstName: "Shawn", lastName: "Carter" }, 'yeezy' : { firstName: "Kanye", lastName: "West" }, 'a-dawg' : { firstName: "Anthony", lastName: "Valera" } } console.table(famousRappers);

console.trace()

See Stack traces in the console documentation for details and examples.

function foo() { function bar() { console.trace(); } bar(); } foo();