0 votes
in JavaScript by
Which of the following is the correct output for the following JavaScript code:

var grade='C';  

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

1 Answer

0 votes
by

Answer: C

Reason: The code of the given program uses a switch statement, in which the value of the expression is compared with the available case labels. If the value matches with any case label, the code written corresponding to that case is executed otherwise the instruction written to the default is executed. Another important point is that switch statements are also used as an alternative to "if-else" statements to reduce the complexity and size of the code.

Related questions

0 votes
asked Mar 20, 2021 in JavaScript by sharadyadav1986
0 votes
asked Mar 21, 2021 in JavaScript by rajeshsharma
...