Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

What will be the output of the following JavaScript 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);

What will be the output of the following JavaScript 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.

Join The Discussion