English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Objet Console JavaScript

console object

The Console object provides access to the browser's debugging console.

The most commonly used feature of the console is to log text and other data.

The simplest way to use logging methods is to output strings:

console.log("Hello world!!!");
test see‹/›

You can also output multiple objects by simply listing them when calling the logging method, as shown below:

var car = "Scorpio";
var myObject = { str: "Some text", id: 12 };
console.log("My first car was a", car, ". The object is:", myObject);
test see‹/›

using%cInstructions apply CSS styles to console output:

console.log("This %cMy %cmessage", "color:white; background-color:black;");
test see‹/›

The text before the instruction is not affected, but the text after the instruction will be styled using the CSS declarations in the parameters.

This code demonstrates how to use multiple%cInstructions apply CSS styles to console output:

console.log("%cThis %cMy %cmessage", 
"color:white; background-color:#4285f4; font-size: 2em;",
"color:#19EE1F; background-color:black; font-size: 2em;",
"color:black; background-color:yellow; font-size: 2em;
test see‹/›

Console object methods

The following table lists the methods of the Console object:

methoddescription
assert()Si le premier paramètre est false, enregistrez le message et le suivi de pile sur la console
clear()Nettoyez la console
count()Enregistrez le nombre de fois où count() est appelé
error()Affichez un message d'erreur sur la console
group()Créez un nouveau groupe inline, tous les outputs suivants sont retraités à un autre niveau. Pour sortir d'un niveau, appelez groupEnd()
groupCollapsed()

Utilisé pour définir les informations de grouping, les informations affichées sous ce code seront à l'intérieur du grouping replié.

Cliquez sur le bouton d'extension pour ouvrir les informations de grouping.

groupEnd()Sortir du groupe inline actuel
info()Affichez un message informatif sur la console
log()Affichez un message sur la console
table()Affichez les données du tableau sous forme de tableau
time()Démarrer un chronomètre (peut suivre le temps nécessaire pour une opération)
timeEnd()Arrêtez le chronomètre précédemment démarré par console.time()
trace()Affichez le suivi de pile sur la console
warn()Affichez un message d'avertissement sur la console