+ 1
What's the output & WHY?
var x,y,z; x = 10%6 != 106; y = 5; z = (x || y > 6)? y + 4: x - 4; x = 2 * y + z; document.write(x);
2 Answers
+ 3
x = true;
y = 5;
z = 9;
x = 2 * 5 + 9 = 19
Output: 19
As for why, (x || y > 6) isn't checking if X OR Y is greater than 6. It's asking, "Is X true OR is y greater than 6?" In this case, X does equal true, so it stops there and executes the true case of the condition. This makes 'z' equal 9. So 2 * 5 is 10, and 10 + 9 is 19.
+ 2
answer is x=19
x=10%6 != 106; evaluates to x=true
10%6 is 4 ,so not equal to 106 , condition is true .so gives true
y=5
z=(x || y>6 )?y+4;x-4; evaluates to z=9
true || 5>6 , as logical or operator is used , so condition is true , so when condition is true it gives value after ? , which is y+4 i.e 5+4 =9
finally x=2*y+z; evaluates to x=19
x=2*5+9 , x=10+9 , x=19