Represent several discrete cases clearly.
- switch
- case
- break
- default
- lookup object
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.
Missing default behavior can leave a result undefined.
Map a status code to a message using switch, then rewrite it with a lookup table.
Open example.html in a browser and edit example.js. Save, refresh, and use the Console and debugger to inspect values.
- 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.