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

.NET OOP Concepts basic things

Object-Oriented Programming (OOP) is a programming paradigm that is based on the concept of "objects", which are instances of clas...

Best for you