Chapter 4: Reading and debugging

The next few are about what happens when the program meets something it did not expect.

Null and undefined

Two ways JavaScript says "nothing here". undefined usually means nothing was ever set, and null usually means someone set it to nothing on purpose. Reading a property of either one crashes the program, with an error you will see often.

Agents like ?., a shortcut that skips the read when the value is missing, because it makes the crash go away. But it swaps an error you would notice for a wrong answer you might not. The real question is what should happen when the value is missing, so ask that, and then have it written down in the code.

Say it to your agent

“user.address can be missing for guest checkouts. Don't add ?. to silence it. Show a "no address yet" message on the page, and add a test with a guest user that checks that message appears.”

The workshop

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