In JavaScript, the console is an object that provides a set of methods for logging messages, debugging code, and monitoring the behavior of a JavaScript program. The console is built into web browsers and Node.js and can be accessed from the browser developer tools or the Node.js command line. Let’s discuss some of the common console methods:
Console.log() :
Console.log is used to output a message on the console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.
Console.error() :
Console.log is used to log an output message to the console. Note: This feature is available in Web Workers.
Console.warn() :
Console.warn() is used to output a warning message to the console. By default, the warning message will be highlighted with yellow color.
Console.info() :
Console.info is used to log an information message to the console. In Firefox, a small “i” icon is displayed next to these items in the Web console’s log.
Console.table() :
Console.table is used to log an array or an object as a table to the console.
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.clear() :
The console.clear()
method clears the console if the console allows it. A graphical console, like those running on browsers, will allow it; a console displaying on the terminal, like the one running on Node, will not support it, and will have no effect (and no error).
I hope you guys find this tutorial helpful. If you do please share it with your friends and bookmark this site for more amazing tutorials. Thanks