Skip to guide content
[js] recap
Chapter 1 · Fundamentals Switch statement

1.7

Switch statement

Examples with a Run button are editable. Underlined terms open a short definition.

Switch Statment

switch (
    new Date().getDay() // input is current day
) {
    case 6: // if (day == 6)
        text = 'Saturday';
        break;
    case 0: // if (day == 0)
        text = 'Sunday';
        break;
    default:
        // else...
        text = 'Whatever';
}

Your last opened chapter is saved in this browser when local storage is available.

Discuss this section

Questions, corrections or a better example? Comments use GitHub Discussions.