HTML DOM console.log() method

Definition and usage

The console.log() method writes messages to the console.

The console can be used for testing purposes.

Tip:When testing this method, make sure the console view is visible (press F12 to view the console).

Instance

Example 1

Write to the console:

console.log("Hello world!");

Try it yourself

Example 2

Write an object to the console:

var myObj = { firstname : "Bill", lastname : "Gates" };
console.log(myObj);

Try it yourself

Example 3

Write an array to the console:

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

Try it yourself

Syntax

console.log(message)

Parameter value

Parameter Type Description
message String or Object Required. Write messages or objects to the console.

Browser Support

The numbers in the table indicate the first browser version that fully supports this method.

Method Chrome IE Firefox Safari Opera
console.log() Support 8.0 4.0 Support Support