Sitemap

CONSOLE

2 min readDec 28, 2022

--

The console is an object that provides access to the browser’s debugging console. It allows you to log messages, warnings, and errors to the console, as well as to inspect and debug JavaScript code.

Some common methods that you can use with the console :

console.log():

It prints a message to the console. You can pass any number of arguments to this method, they will be logged as separate items.it can a string, array, boolean etc.

Example for console.log()

console.error():

It prints an error message to the console. This works the same way as console.log() but it displays the message in a different color (red) toindicate that it is an error.

Example for console.error()

console.warn():

Get Aimanfatimaahmed’s stories in your inbox

Join Medium for free to get updates from this writer.

It prints a warning message to the console. Works the same way as console.log(), but it displays the message in a different color(yellow) to indicate a warning.

Example for console.warn()

console.clear():

It is used for clearing the console, So that you have a clear understanding of future outputs.

Example for console.clear()

console.table():

It prints an array or object as a table in the console. It can be useful for displaying data in a more organized and readable way.

Example for console.table()

console.time() and console.timeEnd():

It allows you to measure the time it takes to execute a piece of code. You can specify a label when calling console.time(), and then call console.timeEnd() with the same label to see how much time has passed/how much the code is taking for executing and returning an output.

Example for console.time() and console.timeEnd()

You can use these methods in your code to help debug and understand what is happening.

--

--