Chapter 4: Reading and debugging

Now the building blocks, in the order you meet them. Each one is easiest to understand by watching it run, so press Step on the instruments below and see what the program is holding at each line.

Variable

A name for a value the program is holding, like a label on a box. In JavaScript, let means the name can be given a new value later, and const means it can't.

Most bugs come down to a variable not holding what someone assumed it held. When you read an agent's code, the question to keep asking is: what is in this name, right now, on this line?

Say it to your agent

“This function reassigns result five times. Give each step its own const, with a name that says what it holds, and change no behaviour. Show me the tests still pass.”

The workshop

Name a word, or describe what you mean in everyday language.