When we start learning JavaScript then at first learn about console.log(); to print the message on the browser. And we think that the JavaScript console has only one method. But that's not true because JavaScript contains a lot of console methods.
So to clear this confusion, in this post we are going to discuss the 10 Most Popular JavaScript console methods.
1). log
The console.log(); method is used to print a message on the web browser's console. This console method can print strings, numbers, arrays, and objects. Instead of displaying any message on the browser console, it logs messages to a debugging console.
2). info
The console.info(); is used to display a message to the browser console. This console method is very similar to console.log(); but it is used by developers for permanent messages to output to the console in their code.
3). warn
As the name suggests warn, this console method is used to print the warning message on the browser console. This console method takes a single argument of a message to be displayed on the browser's console.
4). Error
This JavaScript console method is used to print an error message in the console. It is mainly used for testing and troubleshooting purposes when we want to display any errors. This console method also takes a single argument of any type like String or Object.
5). Count
This console method is used to print a message on the console as the number of times it is called. Or It counts the number of every count and prints it on the browser console.
6). Assert
This javascript console method is used to print messages on the browser's console based on the conditions. It prints the message on the console when the assertion is failed. And if the assertion is true then nothing happens.
7). Time, Timelog and TimeEnd
The console.time(); method is used to start a timer to track the logs in the browser. Before starting the timer method the console.time(); method to start the timer and console.timeEnd(); to end the timer or to stop the timer.
And the console.timeLog(); is used to log the current value of the timer which was started from the previous console.time(); This is not used to start or end of the timer it is used only to print the current timestamp.
8). Group and GroupEnd
As this console method's name suggests that it is used to make a group of messages on the console of the web browser.
And the console.groupEnd(); the method is used to end a message group.
9). Table
This console method is used to print any object in the form of a table in the console of a web browser. To print the object in the form of a table you can use the code given below.
10). Clear
As the name suggests clear. So, this console method is used to clear the messages from the console. It is good to use it at the staring of your code because it will clear all the previous logs but don't use it at the end of your all logs because then it will clear your all messages that you want to see.
🙋🏻♂️ Let me know in the comment section which console method was new for you in this post.