Table of Contents
JavaScript console Methods :
console.assert()
The console.assert() method writes a message to the console, but only if an expression evaluates to false.
console.assert(document.getElementById("demo")),
"You have no element with ID 'demo'");
//Output
//Assertion failed : You have no element with ID 'demo'
console.clear()
The console.clear() method clears the console. It will also write a message in the console: “Console was cleared”.
console.clear();
//Output
// console was cleared
console.count()
Writes to the console the number of times that particular console.count() is called. You can add a label that will be included in the console view.
console.count("myLabel");
console.count("myLabel");
//Output
// myLabel : 1
// myLabel : 2
console.error()
he console.error() method writes an error message to the console.The console is useful for testing purposes.
console.error("You made a mistake");
//Output
// You made a mistake
console.group()
The console.group() method indicates the start of a message group.All messages will from now on be written inside this group.
console.log("Hello world");
console.group();
console.log("this time inside a group!");
//Output
// Hello world!
// console.group
// this time inside a group!
console.groupCollapsed()
The console.groupCollapsed() method indicates the start of a collapsed message group. Click the expand button to open the message group.
console.groupCollapsed();
console.log("this time inside a group!");
//Output
// console.groupCollapsed
// this time inside a group!
console.groupEnd()
The console.groupEnd() method indicates the end of a message group.
console.log("Hello world");
console.group();
console.log("this time inside a group!");
console.groupEnd();
console.log("and we are back.");
//Output
// Hello world!
// console.group
// this time inside a group!
// and we are back.
console.table()
The console.table() method writes a table in the console view. The first parameter is required, and must be either an object, or an array, containing data to fill the table.
console.table(["Audi", "Volvo", "Ford"]);

console.info()
The console.info() method writes a message to the console.
console.info("I Like Coding");
// Output
//I Like Coding
console.log()
The console.log() method writes a message to the console. The console is useful for testing purposes.
console.log("I Like Coding");
// Output
//I Like Coding
console.time()
Use the console.time() method to start the timer. The console.timeEnd() method ends a timer, and writes the result in the console view.
console.time();
for(i=0; i < 100000; i++){
// some code
}
console.timeEnd();
// Output
// default : 2.491943359375 ms
console.warn()
The console.warn() method writes a warning to the console.
console.warn("This is a warning!");
// Output
// This is a warning!
I hope you like this JavaScript console Methods article.
Also Read :
- Tailwind CSS Setup
- Chakra UI Setup
- JavaScript Date Methods
- JavaScript Absolute Beginner’s Guide
- Angular Material Grid Layout Example
- Angular Material Card Example
- Top 10 VS Code extensions