JavaScript syntax: Difference between revisions

Content deleted Content added
Line 1,349:
break;
case ANOTHERVALUE:
// statements for when ANOTHERVALUE || ORNAOTHERONE
// no break statement, falling through to the following case
case ORANOTHERONE:
// statements specific to ORANOTHERONE (i.e. !ANOTHERVALUE && ORANOTHER);
break; //The buck stops here.
case YETANOTHER:
// statements;
break;
Line 1,357 ⟶ 1,363:
</syntaxhighlight>
 
* <code>break;</code> is optional; however, it is usually needed, since otherwise code execution will continue to the body of the next case block. This ''fall through'' behavior can be used when the same set of statements apply in several cases, effectively creating a [[disjunction]] between those cases.
* Add a break statement to the end of the last case as a precautionary measure, in case additional cases are added later.
* String literal values can also be used for the case values.