Published on

More than you know basic console logging in JavaScript

Authors

Overview

While coding with javascript you used console many times. but most of the time most developers just use console.log including myself. but as you know console is an object has many methods using which we can make our debug more effectively than console.log. as you type in browser console you see a list of other methods, which will explain some of the essential methods here.

console.assert()

console.assert() write an error message if the assertion is false, If the assertion is true, will not write anything. console.assert() useful when we want to conditionally write to console something. Since its true condition will not print anything but on chrome browser, you will see undefined. console assert if assertion failed will write an error on the console assertaion failed

console.error( )

console.error() output error to web console. console.error() can be very useful for testing purposes when you want to indicate that there is something breaking within the code console error consle error

console.warn( )

console.warn() will Outputs a warning message to the Web Console. if it's not an important issue then you can show a warning message. note: In Chrome and Firefox, warnings have a small exclamation point icon next to them in the Web Console log. console warn

console.group( ) & console.groupEnd( )

console.group() Creates a new inline group in the Console log. will indents following console messages by an additional level, until console.groupEnd() is called.

console.group() can be useful when you have a collection of messages you want to keep together in good order and with many level. If needed, you can also provide your group with a label. console group

console.table( )

console.table() will display in tabular method. It logs data as a table. Each element in the array/object will be a row in the table. This method takes two parameters, tableData and tableColumns. tableData is required and should be an array/object while tableColumns is optional and is an array containing the names of the columns you want to display. console table

console.time( ) & console.timeEnd( )

console.time() will start a timer in the web console while console.timeEnd() stops the timer and displays the result in the console it's seeing how long it takes your code to run. You can also pass in an optional label parameter.

console.trace( )

console.trace() Will log a stack trace to show how the code ended up at a certain point

console.trace() can be extremely useful when you want to see a trace when your functions are being called. You can also pass in an optional label parameter

You can still use the format specifiers with all methods of console.