- time() and timeEnd()
- group() and groupEnd()
- custom console logs
Let’s look at all these methods one by one.
Mainly used to log(print) the output to the console. We can put any type inside the log(), be it a string, array, object, boolean etc.
Used to log error message to the console. Useful in testing of code. By default the error message will be highlighted with red color.
Used to log warning message to the console. By default the warning message will be highlighted with yellow color.
Used to clear the console. The console will be cleared, in case of Chrome a simple overlayed text will be printed like : ‘Console was cleared’ while in firefox no message is returned.
console.time() and console.timeEnd()
In the above code sample, we can see that the label is ‘abc’ which is same for both the time() and the timeEnd() method. If we increase the amount of code inside the block defined by these methods, then the time will increase. It is also worth remembering that the time returned to the console will be in milliseconds and might be different each time we refresh the page.
This method allows us to generate a table inside a console. The input must be an array or an object which will be shown as a table.
This method is used to count the number that the function hit by this counting method.
console.group() and console.groupEnd()
group() and groupEnd() methods of the console object allows us to group contents in a separate block, which will be indented. Just like the time() and the timeEnd() they also accepts label, again of same value.
Custom Console Logs
User can add Styling to the console logs in order to make logs Custom . The Syntax for it is to add the css styling as a parameter to the logs which will replace %c in the logs as shown in the example below .
Console sidebar is used to organize logs and provides clarity in debugging experience.
After Filtering Errors only using console sidebar :
After Filtering Warnings only using console sidebar :