Tutorial by Examples

In most environments, console.table() can be used to display objects and arrays in a tabular format. For example: console.table(['Hello', 'world']); displays like: (index)value0"Hello"1"world" console.table({foo: 'bar', bar: 'baz'}); displays like: (index)value"fo...
function foo() { console.trace('My log statement'); } foo(); Will display this in the console: My log statement VM696:1 foo @ VM696:1 (anonymous function) @ (program):1 Note: Where available it's also useful to know that the same stack trace is accessible a...
A browser's debugging console can be used in order to print simple messages. This debugging or web console can be directly opened in the browser (F12 key in most browsers – see Remarks below for further information) and the log method of the console Javascript object can be invoked by typing the fol...
console.time() can be used to measure how long a task in your code takes to run. Calling console.time([label]) starts a new timer. When console.timeEnd([label]) is called, the elapsed time, in milliseconds, since the original .time() call is calculated and logged. Because of this behavior, you can ...
console.count([obj]) places a counter on the object's value provided as argument. Each time this method is invoked, the counter is increased (with the exception of the empty string ''). A label together with a number is displayed in the debugging console according to the following format: [label]: ...
Writes an error message to the console if the assertion is false. Otherwise, if the assertion is true, this does nothing. console.assert('one' === 1); Multiple arguments can be provided after the assertion–these can be strings or other objects–that will only be printed if the assertion is fals...
Many of the console's print methods can also handle C-like string formatting, using % tokens: console.log('%s has %d points', 'Sam', 100); Displays Sam has 100 points. The full list of format specifiers in Javascript is: SpecifierOutput%sFormats the value as a string%i or %dFormats the value a...
You can clear the console window using the console.clear() method. This removes all previously printed messages in the console and may print a message like "Console was cleared" in some environments.
console.dir(object) 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 myObject = { "foo":{ "bar":"d...

Page 1 of 1