The switch Statement

The switch statement is useful when one variable or the result of an expression can have multiple values, for each of which you want to perform a different function.

<script>
switch (page)
{
case "Home": document.write("You selected Home")
break
case "About": document.write("You selected About")
break
case "News": document.write("You selected News")
break
case "Login": document.write("You selected Login")
break
case "Links": document.write("You selected Links")
break
}
</script>

The variable page is mentioned only once at the start of the switch statement. Thereafter the case command checks for matches. When one occurs, the matching conditional statement is executed. Of course, a real program would have code here to display or jump to a page, rather than simply telling the user what was selected.