0
Answer 8
Why is the answer is 8? I can’t see any principles
3 Respostas
+ 3
For what question was the answer 8?
+ 3
switch (x) means that every case is compared with the value of x.
In this example, cases 1 & 2 are not carried out because x is not equal to either 1 or 2 (since it is equal to 3). The default case is carried out when none of the other cases are carried out, which is true in this example. The default case prints the value of x plus 5, which, as x is 3, 3+5 = 8. So that is why it returns 8.
0
var x=3
switch (x) {
case 1:
document.write(x);
break;
case 2:
document.write(x+2);
break;
default:
document.write(x+5);
}
the answer is 8