Trying JavaScript in the REPL
In this lesson, you opened Node’s REPL, tried a line of the setup check in it, and left it again.
- Run
nodewith no arguments to open the REPL, the waypythonopens Python’s. Its prompt is>instead of>>>. - Type a line, and the REPL echoes its value, as Python’s does. Strings come back in single quotes.
- The REPL echoes the value of every line. A
console.log()line shows its output, thenundefined, becauseconsole.log()returnsundefined, JavaScript’s word for no value. Python’sprint()returnsNonetoo, but Python’s REPL doesn’t echoNone. A script never echoes, so theundefinednever reaches the report. - The up arrow brings back your last line. The REPL’s own commands start with a dot:
.helplists them, and.exitleaves. Ctrl+D leaves too. node -p "expression"runs one expression from the shell and prints its value, wherepython -cprints only what youprint().
Here’s the session from the video, after the banner:
> "request VPN access"
'request VPN access'
> console.log("1. request VPN access")
1. request VPN access
undefined