0
Confused
Can somebody please explain to me why the output is 12 for this example. I canât understand why it wouldnât be 1? Var sub = âEngâ; Switch (sub) { Case âEngâ: Document.write (1) Case âEsâ: Document write (2)
2 Answers
+ 1
thanks for the response, it was actually one of the questions i was asked in the challenges that I got wrong.
The question that was asked was what is the output of this code? I answered 1 but the correct answer is 12
I just didnt understand why the second case âEsâ part of the statement was executed?
0
https://www.sololearn.com/learn/JavaScript/1139/?ref=app
It is the logic of the switch statement.
Var sub = âEngâ;
Switch (sub) {
Case âEngâ:
Document.write (1)
break; //print 1, jump out of the switch statement
Case âEsâ:
Document write (2)
break; //not really necessary for the last case
Without the break statement all the cases are processed. In your example: Document write (2)