Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST

Basic JavaScript

JS Tutorial JS Syntax JS Variables JS Operators JS If Conditions JS Loops JS Strings JS Numbers JS Functions JS Objects JS Scope JS Dates JS Temporal Dates JS Arrays JS Sets JS Maps JS Iterations JS Math JS RegExp JS Data Types JS Errors JS Debugging JS Conventions JS References JS ECMAScript 2026 JS Versions

JS HTML

JS HTML DOM JS Events JS Projects

JS Advanced

JS Functions JS Objects JS Classes JS Asynchronous JS Modules JS Meta & Proxy JS Typed Arrays JS DOM Navigation JS Windows JS Web APIs JS AJAX JS JSON JS jQuery JS Graphics JS Examples JS Reference


JavaScript Debugging Console

Console Like a Pro

The browser console is the most important debugging tool for JavaScript beginners.

If you learn how to use the console properly, you will find bugs faster and understand your code better.

How to Open the Console

In Chrome or Edge, open the console like this:

  • Right-click anywhere on the page
  • Click Inspect
  • Click the Console tab

Note

The console is where JavaScript shows errors, warnings, and messages from your code.

Always keep the console open when testing new JavaScript code.


console.log()

The most common console method is console.log().

Use it to print values and see what your program is doing.

Examples

Print a message:

console.log("Hello from JavaScript!");
Try it Yourself »

Print variables:

let name = "John";
let age = 25;

console.log(name);
console.log(age);
Try it Yourself »

console.warn()

Use console.warn() to display warnings.

Warnings tell you something might be wrong, but your code can still run.

Example

Warning message:

console.warn("This is a warning!");
Try it Yourself »

Note

Use warnings when you want to highlight something suspicious in your program.


console.error()

Use console.error() to display error messages.

Errors show that something has failed.

Example

Error message:

console.error("Something went wrong!");
Try it Yourself »

Logging Multiple Values

You can log more than one value at once.

Example

Multiple values:

let x = 10;
let y = 5;

console.log("x =", x, "y =", y);
Try it Yourself »

Inspecting Objects

The console is very useful for inspecting objects.

Example

Log an object:

let user = {name: "John", age: 25};

console.log(user);
Try it Yourself »

Note

In the console, you can click the object to expand it and see its properties.


console.table()

Use console.table() to display data in a table format.

Example

Table output:

let users = [
  {name: "John", age: 25},
  {name: "Anna", age: 30}
];

console.table(users);
Try it Yourself »

Note

Tables make it much easier to debug arrays of objects.


Debugging Tip: Stop Guessing

Beginners often guess what the value is.

Professionals log the value and confirm it.

If your code is not working, do not guess.

Use console.log().


Next: Breakpoints, Watch, Scope

Logging is powerful, but sometimes you need to pause code execution.

Next page: Learn how to use breakpoints, step through code, and watch variables live.


×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

-->