Recap

Grade 4, page 11 of 11. A one-minute read.

  • if (condition) { ... } runs a block of code only when the condition is truthy.
  • else { ... } runs when the condition is falsy. Exactly one path is taken.
  • else if lets you check several conditions in order. The first true one wins, so order matters.
  • The falsy values are false, 0, -0, 0n, "", null, undefined and NaN. Everything else is truthy (including "0" and "false").
  • Combine conditions with &&, || and !. Always write the full comparison on both sides of ||.
  • Avoid nesting too deeply. Flatten with else if and && where you can.
  • The ternary operator condition ? a : b picks one of two values.
  • switch compares one value against many exact cases. Don't forget break!

Reading is step one

CurlyScript turns these notes into a game: short questions, an explanation after every answer, and a test at the end of each grade. Free, with nothing to sign up for.

Start learning