Node.js ยท Chapter 3 of 43
The Node.js REPL
REPL stands for Read-Eval-Print-Loop. It's an interactive shell that reads JavaScript, evaluates it, prints the result, and loops for the next input.
Start it by typing `node` in your terminal with no filename. It's great for quickly testing snippets of code.
Using the REPL
Once inside, type expressions and press Enter to see immediate results. Use `.exit` or Ctrl+C twice to leave.
Special commands
The REPL supports dot commands like `.help`, `.exit`, `.clear`, and remembers the underscore `_` variable holding the last result.
Example 1 (javascript)
> 2 + 2
4
> const name = 'Ada'
> `Hi ${name}`Output
4
'Hi Ada'Each line is evaluated immediately and the result is printed.
Example 2 (javascript)
> .exitThe .exit command closes the REPL session.
Key points
- REPL = Read-Eval-Print-Loop.
- Start it by running `node` with no arguments.
- Great for quick experiments and debugging.
- Use `.exit` or Ctrl+C twice to quit.
๐ก Note: The REPL is not meant for full applications โ use it for quick checks only.
