Skip to content
blog
2 min read

Console

Explore the browser console for running JavaScript, debugging code, and handling errors. Learn to open the console, execute commands, and view output.

The browser console is where JavaScript talks to you. It’s also where you can talk to JavaScript — run code, inspect values, and see what’s going wrong.

Opening the Console

  • Chrome / Edge: F12 → Console tab, or Ctrl+Shift+J
  • Firefox: F12 → Console tab, or Ctrl+Shift+K
  • Safari: Enable developer tools in Preferences → Advanced, then Cmd+Option+C

console.log

The most-used tool for seeing what a value is at a given moment:

console.log("hello");
console.log(42);
console.log([1, 2, 3]);
console.log({ name: "Reza", age: 28 });

You can log multiple values at once:

const name = "Reza";
const age = 28;
console.log("name:", name, "age:", age);
// name: Reza age: 28

Other Console Methods

console.warn("this is a warning"); // yellow triangle
console.error("something broke"); // red X — for errors
console.table([
{ name: "a", val: 1 },
{ name: "b", val: 2 },
]);
console.time("label");
// ...code to measure...
console.timeEnd("label"); // prints elapsed time

Reading Errors

When something breaks, the console shows a red error message with a file name and line number. That’s where to look first:

TypeError: Cannot read properties of undefined (reading 'name')
at getUserName (app.js:12)
at main (app.js:5)

Read bottom-up: the call started at main on line 5, reached getUserName on line 12, and that’s where it crashed.

Running Code Directly

You can type JavaScript directly into the console and run it with Enter. Useful for quick experiments without creating a file:

> [1, 2, 3].map(n => n * 2)
< [2, 4, 6]

The console is a REPL — Read, Eval, Print, Loop. It evaluates expressions immediately.