Conditional operator problems in JavaScript?

Let me give you a simple logical problem:-

What will be the output of console.log(1>0)?

If your answer is true than you can proceed to next problem, if your answer is false go visit your Mathematics teacher.

Now What will be the output of console.log(1<2<3)?

If your answer is true great.

Now what will be the output of console.log(3>2>1)?

Well this is the point of this blog the answer is false. See JavaScript operates at two operand at a time, so when you compare 1 to 2 answer will be true or 1. And 1 is smaller than 3, so second case will be true.

But when you compare 3 to 2 answer will be true or 1 and when you compare 1 to 1, answer will be false as one is not greater than 1.

One thought on “Conditional operator problems in JavaScript?

Leave a Reply

Your email address will not be published. Required fields are marked *