Tsallaka zuwa abun ciki
Justice Tech School

Ternary and switch

The ternary operator picks between two values in one expression. switch compares one value with many cases. Remember break to stop falling through.

Example
const age = 20;
console.log(age >= 18 ? "adult" : "minor");
switch ("b") {
  case "a": console.log("A"); break;
  case "b": console.log("B");
  case "c": console.log("fell to C"); break;
  default: console.log("other");
}

Exercise

Ternary symbol.

cond  yes : no

Quiz Test

What does a missing break do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.