In this video, you predicted which lines of a short movie-night script show something in the terminal, then watched Node run the file line by line.
Key Points
- In Node’s REPL, every line you type gets an answer back. Type
2 * 3, and the REPL echoes6. That echo is the REPL helping you try ideas one at a time. - When you run a script with
node, Node starts at the top of the file and goes through it once, from top to bottom. Then the script stops. - A script never echoes a line’s value. A line like
2 * 3;still gets worked out, but nothing shows up. In this script, only theconsole.log()lines put text in the terminal. - Comments don’t print. Node skips a line that starts with
//, including aconsole.log()line that a comment has switched off. - Text in quotes prints without its quotes. When one
console.log()gets two values, Node prints them on one line with a space between.
The Script
Here’s the script from the video, saved as scratch/movie.js: