Console is much more than .log()

console.log()

The console method log() outputs a message to the web console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.

Example:

console.count()

The console.count() method logs the number of times that this particular call to count() has been called.

Example:

let user = "";

function greet() {
console.count();
return "hi " + user;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.count();
OUTPUT
"default: 1"
"default: 2"
"default: 3"
"default: 4"

The label is displayed as default because no explicit label was supplied.

If we pass the variable as the argument to the first invocation of , and the string "alice" to the second:

let user = "";

function greet() {
console.count(user);
return "hi " + user;
}

user = "bob";
greet();
user = "alice";
greet();
greet();
console.count("alice");
OUTPUT"bob: 1"
"alice: 1"
"alice: 2"
"alice: 3"

console.error()

Outputs an error message to the Web Console.

console.error(obj1 [, obj2, ..., objN]);
console.error(msg [, subst1, ..., substN]);

console.clear()

The method clears the console if the environment allows it.

console.clear();

console.warn()

Outputs a warning message to the Web Console.

console.warn(obj1 [, obj2, ..., objN]);
console.warn(msg [, subst1, ..., substN]);

console.trace()

The console interface's method outputs a stack trace to the Web console.

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

foo();
OUTPUT bar
foo
<anonymous>

console.time()

Starts a timer you can use to track how long an operation takes. You give each timer a unique name, and may have up to 10,000 timers running on a given page.

console.time(label);

console.timeEnd()

Stops a timer that was previously started by calling console.time()

console.time("answer time");
alert("Click to continue");
console.timeLog("answer time");
alert("Do a bunch of other stuff...");
console.timeEnd("answer time");

console.info()

The console.info() method outputs an informational message to the Web Console.

console.info(obj1 [, obj2, ..., objN]);

console.table()

Displays tabular data as a table.

console.table(["apples", "oranges", "bananas"]);

Senior Engineer - Wavelabs ( www.wavelabs.ai )

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store