Home of web learners


Switch is used to execute within condition value

Lets do an example

    var a=2;
    switch (a) {
      case 1:
          document.write('This is two');
          case 3:
                document.write('This is three');
                document.write('This is not matched');

Here you see that inside the switch,we use the variable which we are going to check,next we use the case,if this case value matched with the variable value,then those case are going to execute

In this example,it matched with 2,so its shows this is two,then program got break statement and exit from the switch

If no case not matched with the variable value,then it execute default block,here it having a code for showing text,and exit from the switch


About webn3rd