Switch Statement in JavaScript with example

 A switch statement allows you to evaluate multiple conditions, checking for specific values.


Example:


let day = 3;

let dayName;


switch (day) {

    case 1:

        dayName = "Monday";

        break;

    case 2:

        dayName = "Tuesday";

        break;

    case 3:

        dayName = "Wednesday";

        break;

    default:

        dayName = "Unknown Day";

}


console.log(dayName); // Output: Wednesday

Explanation:

The switch statement checks the value of day.
If day is 3, it assigns "Wednesday" to dayName.

No comments:

Post a Comment

Angular URL serializer to properly handle URLs that start with query parameters directly (without a path adding trailing slashes Angular

 Example Code The key requirement: In the parse method, I added special handling for URLs that start with query parameters: If the URL start...

Best for you