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(besked)

Parameter value

Parameter Type Beskrivelse
besked Streng eller objekt Obligatorisk. Skriv beskeder eller objekter til konsollen.

Browserunderstøttelse

Tallene i tabellen angiver den første browserversion, der fuldt ud understøtter denne metode.

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