What is REPL? (Ctrl + Shift + I > console)
REPL (Read-Eval-Print Loop) is an interactive programming environment where you can run JavaScript (or other languages) line by line and see the results immediately.
Breaking it down:
- Read → Takes your input (a JavaScript command).
- Eval → Evaluates (executes) the command.
- Print → Displays the result.
- Loop → Repeats the process for the next command.
Example in JavaScript (Node.js REPL)
- Open your terminal and type:
node - You’ll enter the Node.js REPL (interactive mode). Try this:
Output:
2 + 3;5 - You can also define variables and functions:
Output:
let name = "Rahul";
console.log("Hello, " + name);Hello, Rahul
Why is REPL useful?
- Quick testing of JavaScript code.
- Debugging small code snippets.
- Learning and experimenting with JavaScript without creating a file.