Skip to main content

Menu

System onlineAI Tutorials / 2026

AI Tutorials
Knowledge search

Recent · Popular · Tutorials

  • dart3 tutorials
  • java1 tutorial
  • Javascript3 tutorials
  • Node.js Introduction2 tutorials
  • dartdart · General · In depth
  • JavascriptJavascript · Advanced · In depth
  • JavascriptJavascript · Advanced · Mid
  • JavascriptJavascript · Advanced · Short

Find a tutorial

Tell the assistant what you want to learn. It suggests published chapters.

For example: “I want to learn Rust ownership from the start.” The conversation is kept only in this tab.

0 / 2,000 characters

Enter to send, Shift+Enter for a new line. Do not include personal information.

Chapter 5

Exploring with the REPL

So far, you have written code into a file and run it with the `node` command. That works well, but sometimes you just want to ask JavaScript a quick question: "What does this return?" or "Did I spell that method right?" For that, Node.js has the **REPL**.
Level: GeneralLength: Mid2 min read

Read at another depth

Exploring with the REPL

So far, you have written code into a file and run it with the node command. That works well, but sometimes you just want to ask JavaScript a quick question: "What does this return?" or "Did I spell that method right?" For that, Node.js has the REPL.

REPL stands for Read, Evaluate, Print, Loop. It is an interactive conversation with JavaScript:

  1. Read — Node reads what you typed.
  2. Evaluate — Node runs it.
  3. Print — Node shows you the result.
  4. Loop — Node waits for your next line, then repeats.

Every modern language has a tool like this. Python calls its version the interpreter shell. The REPL is sometimes called a "playground" because it is perfect for trying things out with no files, no setup, and no risk to your project.

Starting and Leaving the REPL

Open your terminal and type:

Code example in bash
node

You will see a prompt that looks like this:

Code example in text
Welcome to Node.js v20.x.x.
Type '.help' for more information.
>

That > is Node waiting for you. Type any JavaScript expression and press Enter:

Code example in text
> 2 + 2
4
> 'hello'.toUpperCase()
'HELLO'
> 5 > 3
true

Notice you do not need console.log. The REPL prints the result of every expression automatically. When you are done, press Ctrl+C twice (or type .exit and press Enter) to leave.

Things Worth Trying

The REPL remembers what you defined, so you can build up small experiments line by line:

Code example in text
> const name = 'Ada'
undefined
> `Hello, ${name}!`
'Hello, Ada!'
> [1, 2, 3].map(n => n * 10)
[ 10, 20, 30 ]

Two small notes on what you see:

  • Assignments like const name = 'Ada' print undefined because the statement itself has no value.
  • The REPL even prints after you press Enter on an incomplete line, letting you continue typing. It understands when your code is not finished, for example when you open a bracket and have not closed it yet.

Handy Shortcuts

The REPL has a few dot commands — special instructions that start with a period:

CommandWhat it does
`.help`Lists all available dot commands
`.exit`Leaves the REPL
`.clear`Resets the session, forgetting your variables
`.save file.js`Saves everything you typed to a file
`.load file.js`Runs a JavaScript file inside the REPL

Two keyboard shortcuts are also worth knowing:

  • Press the up arrow to bring back previous lines, like any terminal history.
  • Press Tab to auto-complete. Type Math., press Tab, and the REPL lists everything the Math object offers — a fast way to discover functions.

When to Use the REPL

The REPL is a tool for questions, not for real programs. Use it when you want to:

  • Check what an expression returns before putting it in your code.
  • Explore how a built-in object, like Math or JSON, behaves.
  • Do quick math or text conversions without opening an editor.

Anything longer than a few lines belongs in a file, where you can save it, edit it, and run it again. A good habit: experiment in the REPL, then copy what worked into your file.

Exercise

What does REPL stand for, and what does each step mean?

Show answer

Read, Evaluate, Print, Loop. The REPL reads the line you typed, evaluates (runs) it, prints the result, and loops back to wait for your next line.

Exercise

You type node in the terminal and see the > prompt. How do you leave?

Show answer

Press Ctrl+C twice, or type .exit and press Enter.

Spotted a mistake, or code that does not work?

Report an issue

Chapter: Exploring with the REPL

0 / 2,000 characters

Plain text, for example: the second code sample does not compile. Do not include personal information.

You can't do that