JavaScript console.log()


Example

Write to the console:

console.log("Hello world!");

More examples below.


Description

The log() method writes (logs) a message to the console.

The log() method is useful for testing purposes.

Note

When testing console methods, be sure to have the console view visible.

Press F12 to open the console veiw.


Syntax

console.log(message)

Parameters

Parameter Description
message Required.
The message to write to the console.

More Examples

Write an object to the console:

const myObj = {firstname:"John", lastname:"Doe"};
console.log(myObj);

Write an array to the console:

const myArr = ["Orange", "Banana", "Mango", "Kiwi"];
console.log(myArr);