Create a Website
CSS Tutorial
FREE Hosting!
With every domain name
you register at DotEasy
you get FREE (no-ad)
one year hosting.
PLUS you get:
  • FREE Website Builder
  • FREE Blog
  • FREE Forum
  • FREE Photo Album
  • FREE Email Accounts
Get your FREE hosting today!
Home > JavaScript Tutorial
$0 Web Hosting

Conditional statements in JavaScript are used to perform different actions based on different conditions.

JavaScript Switch Statement

You should use the switch statement if you want to select one of many blocks of code to be executed.

The Code

  case 1:
    execute code block 1
  case 2:
    execute code block 2
    code to be executed if n is
    different from case 1 and 2

This is how it works: First we have a single expression n (most often a variable), that is evaluated once. The value of the expression is then compared with the values for each case in the structure. If there is a match, the block of code associated with that case is executed. Use break to prevent the code from running into the next case automatically.

Enjoy this tutorial?

1. Link to this page(copy/paste into your own website or blog):
2. Add this page to your favorite social bookmarks sites:
3. Add this page as your favorites. (Press Ctrl+D)