Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Node.Js REPL command prompt

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 350
    Comment on it

    Its  a command prompt like  Unix/Linux shell where we can entered command and get output in interactive mode. REPL, i.e. Read Eval Print Loop, environment is  bundled with Node.Js and REPL performs the following tasks.

    Read – It reads input, parse as JavaScript data-structure and stores in memory.
    Eval – Takes input and evaluates the data structure
    Print - Prints the output
    Loop - Loops the above command until user press ctrl-c twice.
    These feature of Node.Js is useful into debug JavaScript codes.

    Command to start REPL environment on Ubuntu

    Open Terminal and run command...

    $ nodejs
    
    Output like
    $ nodejs
    >

    Simple mathematics Expression on Node.Js REPL
    We can evaluate mathematical operation at Node.js REPL command prompt.
    Example-1:

    $ nodejs
    > 70+30
    100
    >
    
    Here, we added 70 and 30 , output is 100

    Example-2:

    $ nodejs
    > 1 + ( 2 * 5 ) - 6
    5
    >

    Variables in Node.Js REPL command prompt

    We can define variable in two ways

    1. With var Keyword:
    if we defined variable with var keyword then value is stored but not printed i.e.
    
    $ nodejs
    > var y = 70
    undefined
    > 
    
    2. Without var Keyword:
    if we defined variable without var keyword then value is stored but printed i.e.
    
    $ nodejs
    > y = 80
    80
    >

    We can further use the defined variables like...

    $ nodejs
    > x = 70
    70
    > var y = 30
    undefined
    > x+y
    100
    >

    We can print variables using console.log().

    $ nodejs
    > x = 70
    70
    > var y = 30
    undefined
    > z = x+y
    100
    > console.log("Total="+z)
    Total=100
    undefined
    >

    Underscore Variable in Node.Js
    We can use underscore  variable to retrive the last result.

    For example:

    $ nodejs
    > x = 70
    70
    > var y = 30
    undefined
    >  x+y
    100
    > var total = _
    undefined
    > console.log(total)
    100
    undefined
    >

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: