JavaScript Console

Beginner
7 min read
Updated: Nov 2026
3 examples
Debugging

Definition and Usage

In JavaScript, console is the object you use to print messages while a program runs. console.log("Saved") writes Saved to the browser’s DevTools console, or to the terminal when you run the same file in Node.js.

Logging is a side effect. The call prints the value and then returns undefined. Use log() for ordinary values, warn() when something looks wrong, and error() when a step failed. count() tells you how many times a line ran.

This page teaches what the console is. The Console Methods index lists every method in this JavaScript tutorial, including console.log(), console.table(), console.group(), and console.time().

The message is printed. The return value is undefined.

const result = console.log("Saved") prints Saved. result is undefined.

JavaScript Syntax

Common console calls you will meet in a JavaScript tutorial:

JavaScript
console.log("Saved");
console.info("Cache warm");
console.warn("Retrying");
console.error("Request failed");

console.assert(score >= 60, "below passing");
console.count("click");
console.table(rows);

Core Ideas

Ideas every JavaScript console tutorial builds on:

IdeaExampleRemember
Printconsole.log(name)Shows the value, returns undefined
Severityconsole.warn(msg)warn and error are easier to spot
Checkconsole.assert(ok, msg)Prints only when ok is false
Countconsole.count("click")Same label shares one counter
Tableconsole.table(rows)Best for arrays of objects
Timerconsole.time("load")End it with the same label

JavaScript Examples

Three short programs that show how the console works in a JS tutorial. The output below is what those calls print.

Example 1 — Print a value and read the return

log() writes the argument. The variable that catches the call holds undefined.

JavaScript
const score = 80;
const written = console.log(score);

console.log(written);

How It Works

  1. console.log(score) prints 80.
  2. written is undefined, because log() does not return the message.
  3. The second log prints that return value, so the console shows undefined.

Example 2 — Separate notes, warnings, and failures

Use a different method when the message means something different. The text is still just a string.

JavaScript
console.log("Saved");
console.info("Cache warm");
console.warn("Retrying");
console.error("Request failed");

How It Works

  1. log() and info() print ordinary status lines.
  2. warn() prints Retrying. DevTools marks it as a warning.
  3. error() prints Request failed. DevTools marks it as an error.

Example 3 — Count how many times a label runs

Each label has its own counter. A new label starts at 1.

JavaScript
console.count("click");
console.count("click");
console.count("save");

How It Works

  1. The first click prints click: 1.
  2. The same label prints click: 2 on the next call.
  3. save is a different label, so its counter starts at 1.

Next: Console Methods Index

After you know what the console prints, open the methods index for the rest of the calls in this JavaScript tutorial.

Look upWhy
console.log()Print any value while you debug
console.table()Show an array of objects as columns
console.group()Nest related lines under one heading
console.time()Measure how long a block of code takes

Full list: Console Methods index.

Frequently Asked Questions

console is a built-in object for messages you read while debugging. In a browser those messages appear in DevTools. In Node.js they appear in the terminal. console.log() is the method you will use first.
In Chrome, Firefox, or Edge, open DevTools and choose the Console panel (F12). The View Output boxes on this page show the same lines so you can follow the tutorial without leaving the page.
All three print a message. log() is for ordinary values, warn() is for something you should notice, and error() is for a failure. DevTools styles warn and error so they are easy to spot.
It returns undefined. The text you pass is printed as a side effect. If you write const result = console.log("Saved"), result is undefined and the console still shows Saved.
Practice the three examples here, then open the Console Methods index for log(), warn(), error(), table(), group(), time(), and the rest of the methods in this JavaScript tutorial.

Browse every console method

Open the index for log(), warn(), table(), group(), time(), and the rest.

Console Methods index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful