You can open console by using:

Chrome → Ctrl Shift J (on Windows) or Cmd Option J (on Mac) Safari → Option-Cmd-C

The console object provides access to the browser's debugging console. The console object present in the global scope.

console.log(messages)

Outputs a message(variable) to the web console.

console.log("hello");

hello var a =10;

console.log(a);

10 var b = 20;

console.log(a, b);

10, 20 // we can also evaluate expression

console.log(a+b);

30 console.log(`${a} + ${b} = ${a+b}`);

10 + 20 = 30 var obj = {name : "Javascript Jeep"};

console.log(a, b, obj)

10 20 {name: "Javascript Jeep"}

console.clear()

This will remove all the console message and prints Console was cleared .

console.clear();

console.assert(condition, failure message)

The console.assert method is an easy way to run simple assertion tests.

var a = 10; console.assert(a === 10, "This will not be printed"); console.assert(a != 10, "this will be printed", `a = ${a}`);

// Assertion failed: this will be printed a = 10

console.count()

Logs the number of times that this particular call to count() has been called.

function test() {

console.count();

} test(); // default : 1

test(); // default : 2

test(); // default : 3 Example 2 : We can also use label to it function test(label) {

console.count(label);

} test("Times"); // Times: 1

test("Num"); // Num: 1 test("Times"); // Times: 2

test("Num"); // Num: 2 test("Times"); // Times: 3

test("Num"); // Num: 3

console.countReset()

Resets the counter. This function takes an optional argument label .

console.count(); default: 1

console.count(); default: 2

console.count(); default: 3 console.countReset() console.count(); default: 1 console.count("time"); time: 1

console.count("time"); time: 2

console.count("time"); time: 3 console.countReset() console.count("time"); time: 1

Siblings of console.log

console.info()

Prints a message to the console.

console.info("this is a info");

Only in Firefox, a small “i” icon is displayed next to these items in the console’s log.

Other than this, it is similar to console.log method.

console.warn()

Outputs a warning message to the console.

console.warn("this is a warning ⚠️ "); Example let temp = 90; if(temp > 90) {



console.warn("Temp is high"); }

The warning message will be printed with a yellow background.

console.error()

Outputs an error message to the console.