Course contentsShow
← JavaScript
Lesson 21 of 2,7231. JavaScript FoundationsFree lesson

Running JavaScript in the Browser Console

Open DevTools in any browser and execute your first JavaScript statements in the console.

Running JavaScript in the Browser Console

What you'll learn: How to open your browser's developer tools and execute JavaScript code instantly in the console.

Now that you understand JavaScript runs in the browser runtime, it's time to actually use it! Every modern browser includes a console — a built-in interactive environment where you can type JavaScript code and see results immediately. Think of it like a calculator, but for JavaScript: you type something in, press Enter, and get an answer right away.

Opening the Console

In Chrome, Firefox, Safari, or Edge:

  • Right-click anywhere on a webpage
  • Select "Inspect" or "Inspect Element"
  • Click the "Console" tab

Keyboard shortcuts:

  • Windows/Linux: Ctrl + Shift + J (or F12)
  • Mac: Cmd + Option + J

You'll see a blank line with a > symbol — that's your prompt, waiting for instructions.

Your First JavaScript Statement

Type this and press Enter:

2 + 2

The console immediately shows 4. You just executed JavaScript! The browser's engine (V8, SpiderMonkey, or JavaScriptCore depending on your browser) parsed your code, compiled it just-in-time, and returned the result.

Try another:

"Hello"

It echoes back "Hello". Congratulations — you're now writing JavaScript code that runs in a real runtime environment.

Why This Matters

The console is your playground. It's where you'll experiment, test ideas, and debug code. Unlike writing files and refreshing pages, the console gives you instant feedback. This is the browser runtime in action — you're directly interacting with the JavaScript engine.

Key Takeaway: The browser console is an interactive environment where you can type and execute JavaScript instantly, making it perfect for learning and experimentation.