Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Javascript Switch Statement

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 35
    Comment on it

    The JavaScript switch statement is used to execute one code from multiple expressions. It is just like else if statement. But it is convenient than if..else..if because it can be used with numbers, characters etc.

    Syntax:

    switch(expression){ 
    case value1:
    code to be executed;
    break;
    case value2:
    code to be executed;
    break;
    ...... default: code to be executed if above values are not matched; }
    Example
    <!DOCTYPE html>
    <html>
    <body>
    <script>  
    var grade='B';  
    var result;  
    switch(grade){  
    case 'A':  
    result="A Grade";  
    break;  
    case 'B':  
    result="B Grade";  
    break;  
    case 'C':  
    result="C Grade";  
    break;  
    default:  
    result="No Grade";  
    }  
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: