GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.tutorialrepublic.com — JavaScript Switch Case Conditional Statements - Tutorial Republic JAVASCRIPT BASIC
JS Introduction
JS Getting Started
JS Syntax
JS Variables
JS Generating Output
JS Data Types
JS Operators
JS Events
JS Strings
JS Numbers
JS If…Else
JS Switch…Case
JS Arrays
JS Sorting Arrays
JS Loops
JS Functions
JS Objects
JAVASCRIPT & DOM
JS DOM Nodes
JS DOM Selectors
JS DOM Styling
JS DOM Get Set Attributes
JS DOM Manipulation
JS DOM Navigation
JAVASCRIPT & BOM
JAVASCRIPT ADVANCED
JS Date and Time
JS Math Operations
JS Type Conversions
JS Event Listeners
JS Event Propagation
JS Borrowing Methods
JS Hoisting Behavior
JS Closures
JS Strict Mode
JS JSON Parsing
JS Error Handling
JS Regular Expressions
JS Form Validation
JS Cookies
JS AJAX Requests
JS ES6 Features
JAVASCRIPT EXAMPLES
JAVASCRIPT REFERENCE
Advertisements
JavaScript Switch...Case StatementsIn this tutorial you will learn how to use the switch...case statement to test or evaluate an expression with different values in JavaScript. Using the Switch...Case StatementThe switch..case statement is an alternative to the if...else if...else statement, which does almost the same thing. The switch...case statement tests a variable or expression against a series of values until it finds a match, and then executes the block of code corresponding to that match. It's syntax is:
switch(x){
case value1: // Code to be executed if x === value1 break; case value2: // Code to be executed if x === value2 break; ... default: // Code to be executed if x is different from all values } Consider the following example, which display the name of the day of the week. ExampleTry this code »
The Note: In a switch...case statement, the value of the expression or variable is compared against the case value using the strict equality operator ( The switch...case statement differs from the if...else statement in one important way. The switch statement executes line by line (i.e. statement by statement) and once JavaScript finds a To prevent this you must include a The The ExampleTry this code »
Multiple Cases Sharing Same ActionEach case value must be unique within a switch statement. However, different cases don't need to have a unique action. Several cases can share the same action, as shown here: ExampleTry this code »
Advertisements
Advertisements
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |