Running JavaScript in the
Browser Console
Learn to write, test, and debug JavaScript code directly inside your browser: no setup, no installs, instant feedback.
What Is the Browser Console?
Every modern web browser (Chrome, Firefox, Edge, Safari) ships with a built-in set of Developer Tools. Inside those tools lives the Console: a live, interactive environment where you can type JavaScript and see the result immediately.
Why Use the Console?
Anatomy of Developer Tools
How to Open the Console
| Browser | Windows / Linux | macOS |
|---|---|---|
| Chrome | Ctrl + Shift + J | Cmd + Option + J |
| Firefox | Ctrl + Shift + K | Cmd + Option + K |
| Edge | F12 → Console tab | Cmd + Option + J |
| Safari | N/A | Cmd + Option + C |
The REPL Model
The console operates as a REPL: a four-step loop that runs every time you press Enter.
Console vs. Script File
| Feature | Console | Script File (.js) |
|---|---|---|
| Setup needed | None | Text editor + browser |
| Execution | Line-by-line (REPL) | Entire file at once |
| Code persistence | Lost on refresh | Saved to disk |
| Best for | Quick tests, debugging | Full programs, apps |
| Multi-line editing | Shift + Enter | Natural (file editor) |
Your First Console Session
Example 1: Basic Expressions
Example 2: Variables & console.log()
Example 3: Interacting with the Page
Writing Multi-Line Code
Need more than one line? Hold Shift + Enter to start a new line without executing. The console waits until you press Enter alone to run everything.
Useful Console Methods
Console Power Features
Common Mistakes
Console Cheat Sheet
| Action | What to Type / Press | Result |
|---|---|---|
| Open Console | Ctrl+Shift+J | DevTools Console panel opens |
| Run expression | Type code + Enter | Result printed below prompt |
| New line (no run) | Shift + Enter | Cursor moves to next line |
| Previous command | Up Arrow | Last command reappears |
| Clear console | clear() or Ctrl+L | All output removed |
| Print a value | console.log(x) | Value of x printed |
Question 1 of 5
What does REPL stand for in the context of the browser console?
Question 2 of 5
Which keyboard shortcut opens the Console directly in Chrome on Windows?
Question 3 of 5
You type let x = 10; in the console and press Enter. What value is displayed?
Question 4 of 5
How do you write multiple lines of code in the console without executing after each line?
Question 5 of 5
What happens to your console variables and functions when you refresh the page?