DrillLab
第 15 / 105 道15 / 105 · #277

什么是 REPL

What is REPL

先自己答,再往下看Answer it yourself first

一句话:Read-Eval-Print-Loop —— 读一行、求值、打印结果、再等下一行。 终端里敲 node 回车进去的那个交互环境, 以及浏览器 DevTools 的 Console,都是 REPL。

用来干什么:验证一小段语法、试一个 API 的返回值、 快速算个东西。不适合写多行逻辑—— 改一行要重敲一遍。

会追问:「在 REPL 里 let x = 1 会打印什么?」——undefined。 因为它打印的是表达式的值, 而变量声明语句的值就是 undefined。 这个小细节能看出你是不是真用过。

In one line: Read-Eval-Print-Loop — read a line, evaluate it, print the result, wait for the next one. Typing node in a terminal drops you into one, and the DevTools Console in a browser is one too.

What you use it for: checking a bit of syntax, seeing what an API returns, working out a quick number. Not for multi-line logic — changing one line means retyping the lot.

Follow-up: “What does let x = 1 print in a REPL?” — undefined. It prints the value of the expression, and the value of a variable declaration is undefined. A small detail, but it shows whether you have actually used one.