JavaScript console() Methods #1

Gibson Joseph
YavarTechWorks
Published in
4 min readMar 13, 2023

--

JavaScript console methods part #1

Hi There, 👋🏻

I am Gibson, In This blog, we will learn about some console methods with examples. So let’s move on to the topics.

Table of content: đź“‹

Now we will discuss the following topics.

JavaScript console methods

What are console objectsâť“

First, we will see what is console objects. The console object is the global object in JavaScript. The console object provides access to the browser’s debugging console.

With the help of console methods, you can print messages, warnings, and errors to the browser console which is helpful for debugging purposes.

I think we mostly used the console.log() method for debugging. But there are many console methods available. That method makes debugging easier.

The Console object is a property of the Window object.

We can open a console in a web browser by using the following command for Windows and Mac.

windows: Ctrl + Shift + I

Mac: Command + Option + K

console.log()

The console.log method is used to print or log a message. I think we used it mostly. The console.log method takes one or more arguments and prints them.

Example:

  const age = 21;
console.log("My age is", age);

Output:

console.log()

console.info()

The console.info method is similar to the console.log method, which is used to print the information message. I recommend to you to using the console.info() method.

Example:

console.info("Hi there, I am Gibson");

Output:

console.info()

console.warn()

Now we will see the console.warn method. This is used to highlight the warning messages. This method takes one or more parameters, and that parameter can be of any type. It will print the yellow color warning message with a yellow color icon.

Example:

  const age = 16;

if (age < 18) {
console.warn("You are not eligible for a vehicle license.");
}

Output:

console.warn()

console.error()

Now we will see the console.error method. this method is used to print the error message to the console. It will print the red color error message with a red color icon. This is used to highlight the error messages.

Example:

 console.error('network connection error');

Output:

console.error()

console.time() & console.timeEnd() & console.timeLog()

Now we will see what is console.time method. The console.time method is used to calculate how long an operation takes to execute. console.time method is to start the timer and use the console.timeEnd() method when the operation is finished.

And the console.timeLog()method helps us to print the current time. It does not start or end any timers.

This method takes an argument as a string label.

Example:

  console.time("time");
const arr = [1, 2, 3, 4];
for (let i = 0; i < arr.length; i++) {
// some code
}
console.timeEnd("time");

Output:

console.time() & console.timeEnd() & console.timeLog()

And with this, we learned some console methods with some basic examples. In my next blog, we will see more console methods.

--

--

Gibson Joseph
YavarTechWorks

Web developer | current learn front-end | Daily improving skills | Tech Blogger | I share my Knowledge related to web development |