PDA

View Full Version : Javascript Console Methods You Must Know



charlesprabhu
02-21-2023, 02:06 AM
Console.table()
This function takes one mandatory argument data, which must be an array or an object, and one additional optional parameter columns.
It logs data as a table. Each element in the array (or enumerable property if data is an object) will be a row in the table.

Console.group()
The *console.group()* method creates a new inline group in the Web console log, causing any subsequent console messages to be indented by an additional level, until *console.groupEnd()* is called.
You can use nested groups to help organize your output by visually associating related messages.

Console.assert()
The *console.assert()* method writes an error message to the console if the assertion is false. If the assertion is true, nothing happens.

Console.trace()
Use the *console.trace* method to output a stack trace.
This can be useful for understanding the flow of execution in your code and for identifying where a particular log message is coming from.

Console.dir()
The method console.dir() displays an interactive list of the properties of the specified JavaScript object. The output is presented as a hierarchical listing with disclosure triangles that let you see the contents of child objects.

Console.count()
The *console.count()* method logs the number of times that this particular call to count() has been called.

Console.profile()
Use the *console.profile*and *console.profileEnd* methods to measure the performance of a block of code.
This can be useful for identifying performance bottlenecks and for optimizing your code for speed and efficiency.