Question presented to candidate: "Running node with no file arguments drops you into a prompt where you can type JavaScript directly. What is actually happening there, and is that prompt the same thing as running a .js file?"
What a strong answer should cover:
- REPL stands for Read-Eval-Print Loop: Node reads one line/expression of input, evaluates it, prints the result, and loops back for the next input — running
nodewith no file argument starts this interactive session. - It shares Node's actual JavaScript engine and standard library with any script — the REPL is not a separate, limited "toy" interpreter;
require(), built-in modules, and full language features are all available inside it. - 📌 A concrete, verifiable feature: the REPL keeps a special variable,
_, always holding the result of the last evaluated expression — genuinely usable in the next line, not just documented behavior. - Multi-line input (an unfinished object literal, an open block) is handled by the REPL detecting the incomplete expression and prompting for continuation, rather than evaluating a syntactically broken partial line.
- Special dot commands exist specifically for the REPL context:
.exit,.help,.editor(a multi-line paste-friendly mode),.save/.load(persisting/reloading session history to/from a file) — these are REPL-specific, not valid inside an ordinary script. - A precise answer distinguishes the REPL's use case (quick, interactive exploration — checking how an API behaves, testing a small expression, inspecting a value) from a script file's use case (the actual, repeatable, version-controlled application logic) — the REPL is explicitly not the place application code lives.
Clarifying questions expected:
- "Is the interviewer asking about the interactive CLI experience, or Node's programmatic
replmodule for building a custom REPL into an application?" — both exist and are related but distinct. - "Is there a specific dot command or REPL behavior the question is really getting at?"
Code / implementation expected: Optional for the interactive-CLI framing; showing the programmatic repl module actually evaluating input (including the _ variable) is a strong, concrete way to demonstrate real understanding rather than surface familiarity.