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 Methods in JavaScript 💥 console.log statement](http://saqibz.com/wp-content/uploads/2023/05/console.log-message.png)
Console.error() :
Console.log is used to log an output message to the console. Note: This feature is available in Web Workers.
![Console Methods in JavaScript 💥 Console.error()](http://saqibz.com/wp-content/uploads/2023/05/console.error-screen.png)
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 Methods in JavaScript 💥 console.warning screen](http://saqibz.com/wp-content/uploads/2023/05/console.warning-screem.png)
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 Methods in JavaScript 💥 console.info screen](http://saqibz.com/wp-content/uploads/2023/05/console.info-screen.png)
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 Methods in JavaScript 💥 console.table screen](http://saqibz.com/wp-content/uploads/2023/05/console.table-screen.png)
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).
![Console Methods in JavaScript 💥 console.clear screen](http://saqibz.com/wp-content/uploads/2023/05/console.clear-screen.png)
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