Skip to content

Latest commit

 

History

History
36 lines (23 loc) · 912 Bytes

File metadata and controls

36 lines (23 loc) · 912 Bytes

10. Switch and decision tables

Represent several discrete cases clearly.

Learn

  • switch
  • case
  • break
  • default
  • lookup object

How it works

Switch compares a value against cases and needs break to avoid accidental fall-through. For simple value mappings, an object or Map can be easier to extend. Always consider an unknown case.

Common mistake

Missing default behavior can leave a result undefined.

Guided challenge

Map a status code to a message using switch, then rewrite it with a lookup table.

Run the example

Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.

Completion check

  • Explain the core idea in your own words without reading the code.
  • Change one input and predict the output before running it.
  • Test one boundary or failure case, then record what you changed.