Well the term REPL mainly stand for "Read Eval Print and Loop". And this will specifies a computer environment like a window console or a Unix/Linux shell where we can enter the commands. And once we input the commands system will responds an output in an interactive mode.
REPL Environment
Node.js or node will come in bundled with REPL environment. And each part of the REPL environment has a specific work.
Read:This will reads users input; and parse the input into JavaScript data-structure and stores in memory.
Eval:This will takes and evaluates the data structure.
Print:This will print the result.
Loop:This will loops the above command until user will press ctrl-c twice.
How to start REPL
And to start REPL by simply running "node" on the command prompt as given below:-
And you can execute various mathematical operations on REPL Node.js command prompt.
Node.js Simple Expressions
Once you start REPL node command prompt you can put any mathematical expression:-
Example:>10+20-5
25
Example2:>10+20+(4*5)/7
Using variable
Well variables are used to store values and print later. If you do not use "var" keyword then value is stored in the variable and printed and on another hand if "var" keyword is used then value is stored but not printed. And you can print variable by using console.log().
Node.js Multiline expressions
Node REPL also support multiline expressions like JavaScript. Below multiline code have the do-while loop example:-
var x = 0
undefined
> do {
...x++;
...console/log("x:" + x);
...} while ( x< 10);
Node.js Underscore Variable
Well we use _ underscore to get the last result. Below example will helps you understand the _.
Node.js Exit REPL
to exit in REPL you need to use ctrl+c command twice to come out of Node.js.
Node.js REPL Commands
Below are some important REPL commands used in REPL.