JavaScript console.log()

JavaScript console.log()

All modern browsers have a web console for debugging. The console.log() method is used to write messages to these consoles. For example,

When you run the above code, 44 is printed on the console.

To learn more about using a console, visit: JavaScript Getting Started.


console.log() Syntax

Its syntax is:

console.log(message);

Here, the message refers to either a variable or a value.


Note: We will be using the console.log() method to display the output in our upcoming lessons.


Example 1: Print a Sentence

Output

I love JS

Example 2: Print Values Stored in Variables

Output

Hello Jack

As you can see from these examples, console.log() makes it easier to see the value inside a variable. That's why it's commonly used for testing/debugging code.

The console object also has various methods other than console.log(). To learn more, visit JavaScript console.