DEV Community

Hayes vincent
Hayes vincent

Posted on

Java script(switch)

Switch Control Flow

Based on a condition, switch selects one or more code blocks to be executed.

switch executes the code blocks that matches an expression.

switch is often used as a more readable alternative to many if...else if...else statements, especially when dealing with multiple possible values.

let day=2;
        switch (day) {
            case 1:
                console.log("good morning");   
            break;
            case 2:
                console.log("good evening");
                break;
                case 3:
                console.log("good night");
                break      
            default:
                console.log("bad morning");

                break;
        }


Enter fullscreen mode Exit fullscreen mode

Top comments (0)