JavaScript:
Using an interactive shell (REPL)
How to:
Node.js ships with a REPL accessible via the terminal. Pop it open, and you’re ready to roll. Here’s a taste:
$ node
> let sum = (a, b) => a + b;
undefined
> sum(5, 10);
15
> .exit
Straightforward, right? Define variables, functions, or run loops. When done, .exit
takes you back to the real world.
Deep Dive
REPLs have been around since the 1960s – LISP pioneered the concept. The idea: give immediate feedback to the programmer. Alternatives? Besides Node.js REPL, there’s browser-based consoles like Chrome DevTools, online sandboxes like JSFiddle, or full IDEs like VSCode with interactive playgrounds.
Under the hood, REPL workflows typically:
- Read input
- Compile and execute code
- Print output
- Loop back
It’s a simple yet effective cycle that has massively influenced interactive coding.