Try Code in the Node REPL

In the last lesson, you gave Node a file, scratch/check.js, and it ran the line inside and printed a message. Node can also work without a file. You start it on its own, type one line of JavaScript, press Enter, and see the answer right away.

That quick back-and-forth is perfect for trying things out. You can guess what a line will do and check your guess a second later. The arithmetic and text you’ll try here don’t touch any of your files, so you can experiment freely.

In this lesson, you’ll start Node’s interactive mode, try small calculations and text, read Node’s output, recover from an error, and leave again. Keep VS Code open next to this page and type along as you read.

Start the Node REPL

Open your js-course folder in VS Code and choose Terminal → New Terminal, just like in the last lesson. Check that the prompt includes js-course. Then type node on its own, with no filename after it, and press Enter.

Language: Shell
$ node
Welcome to Node.js v26.13.0.
Type ".help" for more information.
>

Node greets you with its version number and then shows a lone >. This is Node’s own prompt, and it means Node is waiting for a line of JavaScript.

This interactive mode is called the REPL, short for read, evaluate, print, loop. Node reads the line you type, evaluates it to work out its value, prints the result, and then loops back to the > to wait for your next line.

The prompt tells you who’s listening. A prompt with your folder name in it belongs to the terminal, which expects commands like node -v. A bare > belongs to Node, which expects JavaScript. On Windows, the terminal’s prompt also ends in >, so look for the folder name in front of it.

Do Arithmetic at the Prompt

Start with a calculation. Type 2 + 3 after the > and press Enter.

Language: JavaScript
> 2 + 3
5

Node answers 5 on the next line, and a fresh > appears below it. The answer it prints is called the echo: what your line works out to, shown straight back to you. In the REPL, every line you type gets its result echoed.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.