Beyond console.log
There are many ways of capturing information in the console.
These different types can be sorted in the browser console to make it easier to find the required information.
console.log
This is the main method used that displays the provided data to the console -
console.error
These are distinguished as errors and are printed in red making them stand out -
console.warn
These are distinguished as warnings and are printed in amber -
console.info
These are distinguished as information in the console -
console.debug
These are just for debugging purposes and are often hidden by default. To display them ensure that verbose is selected in the console settings.
console.table
console.table() allows you to display data as a table. This can be very helpful when working with arrays or objects.
console.time() and console.timeEnd()
These methods are used to measure the time taken for a piece of code to execute.
console.count
console.count() is used to count the number of times a code block is executed.
console.group() and console.groupEnd()
These methods allow you to group together multiple log messages.
console.assert
console.assert() writes a message to the console only if an assertion is false.
In the above example since x is not greater than 10, the message will be printed.
Styling Console Logs
You can style console log messages using CSS.