Console Methods in JavaScript ๐Ÿ’ฅ

Console Methods in JavaScript
Console Methods in JavaScript

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.log statement
console.log statement

Console.error() :

Console.log is used to log an output message to the console. Note: This feature is available in Web Workers.

Console.error()
Console.error()

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.warning screen
console.warning screen

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.info screen
console.info screen

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.table screen
console.table screen

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.clear screen
console.clear screen

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