Your first JavaScript
Run JavaScript in an interactive Node.js shell
⏱ Est. ~8 min
01 · Read
Node.js has an interactive mode called the REPL (Read-Eval-Print Loop). You type a line of JavaScript, Node reads it, runs it, prints the result, and waits for the next line.
It's like having a conversation with JavaScript. You say something, it responds. Great for trying things out and learning — no files, no setup, just you and the language.
💡 Picture thisThe REPL is like a souped-up calculator. A calculator does math. The REPL does math, processes text, runs logic, and anything else JavaScript can do.
Key points
- REPL stands for Read-Eval-Print Loop
- Great for quick experiments
- Type .exit or press Ctrl+C twice to leave
02 · Real-machine exercise
Type node (with no arguments) to start the Node.js REPL. You'll see a > prompt appear — that means Node is waiting for your JavaScript.
node
03 · Real-machine exercise
Now try some JavaScript expressions. Type each one and press Enter to see the result:- 2 + 2 — basic math - "Hello".toUpperCase() — text processing - Math.random() — generates a random number between 0 and 1 Every time you press Enter, Node executes your code and immediately shows the result.
2 + 2
"Hello".toUpperCase()
Math.random()
04 · Quiz
What does console.log() do in JavaScript?
- Saves data to a file
- Prints a message to the terminal or browser console
- Creates a new variable
- Opens a log file
05 · Fill in the blank
To start Node.js's interactive mode, type _____ in your terminal.
06 · Real-machine exercise
Now try console.log() — this is how JavaScript prints output. Then press Ctrl+C twice (or type .exit) to leave the REPL.
console.log("I am writing JavaScript")07 · Quiz
You type node in the terminal and see a > prompt. What happened?
- Node.js is installing packages
- Your terminal is broken and waiting to be fixed
- You're in the REPL — Node is waiting for you to type JavaScript
- Node.js is running a file called node
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.