Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

JavaScript Dictionary

  1. Home
  2. JavaScript Dictionary
  3. console.log() / error() / warn() / table()

console.log() / error() / warn() / table() Since: ES5(ECMAScript 2009)

Outputs messages and data to the console in the browser's developer tools. This is the most commonly used method for debugging.

Syntax

console.log(value);      // General message
console.error(value);    // Error message
console.warn(value);     // Warning message
console.table(array);    // Display in table format

Method List

MethodDescription
console.log()Outputs a general message. You can output any value, including strings, numbers, objects, and arrays. Multiple values can be output at once by separating them with commas.
console.error()Outputs an error message in red. A stack trace is also displayed, making it easier to identify where the error occurred.
console.warn()Outputs a warning message in yellow. Use this when something is not an error but still requires attention.
console.table()Displays arrays or objects in a readable table format.
console.time("label")Starts a timer. Use this to measure how long a process takes.
console.timeEnd("label")Stops the timer started by console.time() and outputs the elapsed time.
console.group("label")Groups console output together. Useful for organizing nested log entries.
console.groupEnd()Ends the group started by console.group().

Sample Code

// Basic output
console.log("Hello"); // Outputs 'Hello'.
console.log(42); // Outputs '42'.
console.log({ name: "Taro", age: 25 }); // Outputs the object.

// Output multiple values separated by commas.
var x = 10;
console.log("Value of x:", x); // Outputs 'Value of x: 10'.

// Errors and warnings
console.error("Failed to fetch data");
console.warn("This function is deprecated");

// Display in table format.
var users = [
	{ name: "Taro", age: 25 },
	{ name: "Hanako", age: 30 }
];
console.table(users);

// Measure processing time.
console.time("loop");
for (var i = 0; i < 100000; i++) {
	// Some processing
}
console.timeEnd("loop"); // Outputs elapsed time like 'loop: 2.5ms'.

// Grouping
console.group("User Info");
console.log("Name: Taro");
console.log("Age: 25");
console.groupEnd();

Overview

console.log() is the most frequently used debugging method in JavaScript development. Whenever you want to check a variable's value or trace the flow of execution, you can quickly output a message to the console.

console.error() and console.warn() are color-coded in the console, making it easy to spot errors and warnings among a large number of log entries. console.table() displays the contents of arrays and objects in a neatly organized table, which is especially handy when you need to understand a data structure at a glance.

console.log() is intended for debugging during development. It is recommended to remove any unnecessary console.log() calls before releasing to production. Excessive log output can affect performance, and internal information may become visible to users.

Browser Compatibility

Chrome Chrome
49+
Supported in all versions
Firefox Firefox
57+
3.5 or earlier ×
Safari Safari
18+
2 or earlier ×
Edge Edge
80+
11 or earlier ×
IE IE
11+
7 or earlier ×
Opera Opera
48+
10 or earlier ×
iOS Safari iOS Safari
18+
Supported in all versions
Android Browser Android Browser
37+
4 or earlier ×
Chrome Android Chrome Android
36+
17 or earlier ×
Firefox Android Firefox Android
79+
3 or earlier ×

If you find any errors or copyright issues, please .