What will be the output of the following JavaScript code? [code] var grade='B'; var result; switch(grade) { case 'A': {

Tiên Hương

New member
What will be the output of the following JavaScript code?
Code:
var grade='B';  
var result;  
switch(grade)
{  
    case 'A':
    {  
        result+="10"; 
        break;
    } 
    case 'B':
    {  
        result+=" 9";
        break;
    }  
    case 'C':
    {  
        result+=" 8";
        break;
    }  
    default:  
    result+=" 0";  
}  
document.write(result);
A. 10
B. 9
C. 8
D. 0
 
Answer: b
Explanation: The above code contains a switch loop. It is used as an alternative to if else statement. One of the given condition is satisfied according to the input of the switch case and the output is decided accordingly.
 

Tìm kiếm

Back
Top