Curriculum

Curriculum

Tell Apart Zero, Empty Text, and Missing Data

Scenario

A quiz app receives a student’s score field in three different forms.

Selected choicePick a choice below
Result—

Try it yourself

Select each value and see why checking "if (!score)" mistakes a valid zero for missing data.

Reveal the explanation
  1. score = 0 (student answered 0 questions right)

    Valid numeric score! Must return "Try again", NOT "Missing score".

  2. score = "" (blank text box submitted)

    Empty text, not a number. Must return INVALID_SCORE.

  3. score = null / None (field omitted)

    Missing data. Must return INVALID_SCORE explicitly.

Never write "if (!score)" when 0 is a valid input. Check explicitly for null/undefined and integer type so 0 stays a valid score.

Review first

Your turn

Explain what happens to freeSeats = 0 if someone writes "if (!freeSeats) return INVALID_FREE_SEATS".

Common mistake Treating 0 free seats as missing input instead of a valid full room.

Check your work

freeSeats = 0 is valid and must return false (Decline), while null/undefined returns INVALID_FREE_SEATS.

Quick check

Which value represents a valid full room rather than missing data?
Show the answer and reasoning

Correct answer freeSeats = 0

Zero is a concrete, valid integer count showing the room currently has no open seats.