Skip to content

read-eval-print loop (REPL)

A read-eval-print loop (REPL) is an interactive prompt that reads one piece of code, evaluates it, prints the result, and then waits for the next input.

In JavaScript, the best-known REPL is the one Node.js starts when the node command runs with no arguments. Browser developer tools offer the same loop in their console panel, and runtimes such as Deno and Bun ship their own.

Every prompt runs in one shared session, so a binding declared at one prompt is still there at the next. The REPL prints a result for every input, which is why a const declaration shows undefined. The Node.js REPL runs input in sloppy mode rather than as an ES module, yet it still accepts top-level await.

The REPL is a host feature. ECMA-262 doesn’t define one, so each runtime decides its prompt, commands, and output format.

Example

Say a developer totals a shopping cart at the Node.js prompt and then wants to add tax without retyping the total. Node.js keeps the value of the last expression in the special variable _:

Language: JavaScript
> const prices = [12.5, 5, 42.5];
undefined

> prices.reduce((total, price) => total + price, 0)
60
> _ * 1.2
72

The declaration prints undefined because it has no value of its own. The reduce() call prints the total, and _ picks that total up for the next prompt.

When a prompt throws, for example because of a typo in a variable name, Node.js stores the error in the special variable _error:

Language: JavaScript
> totl * 1.2
Uncaught ReferenceError: totl is not defined
> _error.name
'ReferenceError'

The thrown ReferenceError doesn’t end the session, so the next prompt can inspect it. Both _ and _error exist only in the Node.js REPL, not in programs.

Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.


By Leodanis Pozo Ramos • Updated Nov. 20, 2026