Which of the following is the correct output for the following JavaScript code

var x=3;
var y=2;
var z=0;
If(x==y)
document.write(x);
elseif(x==y)
document.write(x);
else
document.write(z);

  1. 3
  2. 0
  3. Error
  4. 2
1 Like

The answer is 0 here.

Explanation:
Both the conditions of if (x==y) are false.
As a result, the other part will be printed. So the answer is that the value of Z is 0.