Playground
The real playground is the node command on your own machine. The
scratchpad underneath runs in this page, prints the way Node prints, and was checked to
print exactly what Node printed for the same code when this page was built.
The real playground is one command
Typing node with no arguments gives you the > prompt, which
evaluates each line as you type it. It is the fastest way to answer "what does this actually
do". .exit or Ctrl+D leaves it.
$ node
Welcome to Node.js v26.7.0.
Type ".help" for more information.
> 0.1 + 0.2
0.30000000000000004
> [1, 2, 3].map((n) => n * 2)
[ 2, 4, 6 ]
> .exit
A transcript of an interactive session: it shows what your own terminal does, and an interactive prompt cannot be driven by a build. Both results it shows are checked for real in lessons 5 and 12.
For anything longer than a line or two, put it in a file and run that instead:
node scratch.mjs. node --watch scratch.mjs re-runs it every time
you save, which is the closest thing to a live playground there is.
A scratchpad that runs here
Edit it and press Run. It has the same check() the lessons use.
example.mjs
// Try something. check(name, got, want) prints ok or FAIL.
const counts = (words) => {
const tally = new Map();
for (const w of words) tally.set(w, (tally.get(w) ?? 0) + 1);
return tally;
};
const result = counts(["a", "b", "a"]);
console.log(result);
check("counting words", result, new Map([["a", 2], ["b", 1]]));
What node printed, when the build ran it
node example.mjs
Map(2) { 'a' => 2, 'b' => 1 }
ok counting words