Skip to content

Files

Latest commit

 

History

History
28 lines (22 loc) · 532 Bytes

default-case.md

File metadata and controls

28 lines (22 loc) · 532 Bytes

Pattern: Missing default clause in switch statement

Issue: -

Description

Switch statements should include a default case to handle unexpected input values. Even if the default case is empty, its presence makes the code's intent explicit and helps prevent bugs from unhandled cases.

Examples

Example of incorrect code:

switch (foo) {
  case 1:
    break;
}

Example of correct code:

switch (foo) {
  case 1:
    break;
  default:
    // handle unexpected values
    break;
}