+ 1

What is the output ? Can anyone explain the process of this code?

<script> var a=10, b=20,c=30; if(c>b>a){ document.write('1'); }else { document.write ('2'); } </script>

26th Apr 2019, 4:09 PM
KHUSHbu
KHUSHbu - avatar
2 Respostas
+ 2
Operator precedence is left to right, so (30 > 20 > 10) is interpreted as ((30 > 20) > 10) which produces (true > 10) and since true is counted as 1 the expression returns False. Thus, the else block is executed and the number 2 is printed.
26th Apr 2019, 4:22 PM
Diego
Diego - avatar
+ 2
Ohk Thank you 😊
26th Apr 2019, 5:20 PM
KHUSHbu
KHUSHbu - avatar