Beginner Fundamentals
The Node.js REPL
The REPL (Read Eval Print Loop) is an interactive shell that comes with Node.js. It reads what you type, evaluates it, prints the result, and waits for more. It is perfect for quick experiments.
Starting the REPL
Type node in your terminal with no file name and press Enter. You will see a > prompt where you can type JavaScript.
Trying expressions
// At the > prompt
2 + 3 // 5
"hi".toUpperCase() // 'HI'
const x = 10
x * x // 100
The REPL prints the value of each expression automatically.
Useful commands
.helpshows all REPL commands..clearresets the current context..exitquits the REPL (or press Ctrl+C twice).
The special variable _
The underscore holds the result of the last expression:
5 * 5 // 25
_ + 1 // 26
Summary
The REPL is a fast playground for testing small pieces of code without creating a file. Use it to learn and explore the language.