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=’A’;
var result;
switch(grade)
{
case ‘A’:
result+=”10″;
case ‘B’:
result+=” 9″;
case ‘C’:
result+=” 8″;
default:
result+=” 0″;
}
document.write(result);

What will be the output of the following JavaScript code?
var grade=’A’;
var result;
switch(grade)
{
case ‘A’:
result+=”10″;
case ‘B’:
result+=” 9″;
case ‘C’:
result+=” 8″;
default:
result+=” 0″;
}
document.write(result);
a) 10
b) 27
c) 8
d) 0

Answer: b
Explanation: The above code does not have a break statement after the cases in the switch loop. Therefore all of the cases following “A” will get executed.

Join The Discussion