October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Run JavaScript in the Browser Console: A Beginner’s Guide

Start experimenting with JavaScript in a modern browser: open the developer-tools Console, run a simple expression, and use console.log() to inspect values.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can start coding JavaScript with just a modern web browser: open its developer tools, select the Console, and enter a small expression such as 2 + 3. The Console evaluates what you type and shows the result. From there, you can try console.log() to display values and, once you are comfortable, experiment with code that interacts with the page currently open.

What the JavaScript Console does

A browser’s developer-tools Console is an interactive place to enter JavaScript and see what it returns. Chrome describes it as a REPL—“Read, Evaluate, Print, and Loop”—because it reads an expression, evaluates it, prints a result, then waits for your next input. Chrome DevTools: Run JavaScript in the Console explains this workflow; MDN’s JavaScript introduction also describes using a browser console to enter and run code.

As an Amazon Associate I earn from qualifying purchases.

The Console is useful for learning and quick experiments. It is not the same as a full code editor or a saved JavaScript file: what you enter is evaluated in the browser session, and page-related code acts on the page that is currently loaded.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Open the Console

Open your browser’s developer tools and choose the Console tab. The exact menu labels and keyboard shortcuts depend on the browser and operating system. In Chrome, the documented shortcuts are Control+Shift+J on Windows, Linux, and ChromeOS, and Command+Option+J on macOS. If a shortcut does not work, open the browser’s developer-tools menu and select Console.

Run your first JavaScript

Try an expression

Type this into the Console and press Enter:

2 + 3

The Console evaluates the expression and displays 5. You can try other simple expressions, such as 10 * 4 or "hello".toUpperCase(). The displayed result is the value produced by the expression.

Use console.log() to display a value

Now enter:

console.log("Hello, JavaScript!")

console.log() explicitly writes its argument to the Console. That differs from entering 2 + 3 by itself: the first example asks JavaScript to log a value, while the second is an expression whose result the interactive Console displays. MDN documents console.log() and other Console methods in its Console API reference.

Store and inspect a value

A variable gives a value a name. Enter these as two separate lines:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const name = "Ada";
console.log(name);

The first line declares a constant named name; the second logs its value. Try changing "Ada" to another name and running the lines again. Because name was declared with const, do not redeclare the same name in the same Console session; use a different variable name, or reload the page to start a fresh session.

Try code that interacts with the current page

In a browser Console, JavaScript can use page APIs such as document. For example, Chrome’s tutorial demonstrates changing the text of a button on the currently loaded page with code like this:

document.getElementById("my button").textContent = "New button text";

This only works if the current page contains an element whose id is exactly my button; otherwise, there is no matching button to update. The example changes the live page, not a permanent source file, so reloading the page may undo the change. Do not assume every website has a button with that ID—inspect or use a page you control before adapting the example.

When the result is unexpected

Read the first error message shown in the Console, then check the code around the reported location. A small typo can prevent a whole line from running. MDN recommends logging intermediate values as a debugging aid; MDN’s guide to finding what went wrong covers the browser’s debugging tools.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Check that names are spelled consistently and capitalization matches.
  • Check that parentheses, quotation marks, and brackets are paired.
  • Use console.log(value) to see the value of an expression or variable while investigating.
  • For page code, confirm that the expected element exists on the current page and that its identifier matches exactly.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Browser Console or Node.js?

Both environments can run JavaScript and provide console-style output, but they do not run in the same context. A browser Console is tied to the current page; Node.js runs JavaScript in a Node process outside that page. The Node.js documentation describes its own Console API; that versioned reference should not be taken to describe every Node release identically.

What differs Browser DevTools Console Node.js
Execution context The currently loaded browser page A Node.js process, not the current browser page
Getting started Available in a modern browser’s developer tools Requires a Node.js runtime
APIs Can access page and DOM APIs such as document, when available in that page context Provides Node-specific APIs; browser page objects such as document are not part of the Node Console context
Output context Results and logged values appear alongside the page’s developer tools Console output belongs to the Node process environment

For a first expression or a quick console.log() example, the browser Console is a convenient place to begin. Node.js is a separate option when your goal is to run JavaScript outside a browser page.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.