Why if else condition is giving wrong output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why if else condition is giving wrong output?

if(1<2<3){ console.log("true"); } else{ console.log("false"); } //output is true of above condition if(3>2>1){ console.log("true"); } else{ console.log("false"); } //output is false of above condition why is this happening both condition are true ?

11th Jun 2020, 12:44 PM
Vaibhav Dadhich
Vaibhav Dadhich - avatar
5 Answers
+ 3
3>2 results in True which evalutes to 1 when compared with 1 so 1>1 is obviously false
11th Jun 2020, 1:14 PM
Abhay
Abhay - avatar
+ 2
it might be because 3 > 2 = true which is also 1...and 1 > 1 is false. The > operation takes 2 arguments so the computer can't process the whole line the way you're seeing it.
11th Jun 2020, 1:13 PM
George Samanlian
+ 2
First: (1<2<3) This has two part. 1st : 1<2 = true , true=1, 2nd : so 1<3= true. Finally the result is true. Second: 3>2= true.true=1. Than 1> 1. false. Finally the result is false.
11th Jun 2020, 2:12 PM
Md Iftakher Hossain
Md Iftakher Hossain - avatar
+ 1
Martin Taylor , am I right?
11th Jun 2020, 2:15 PM
Md Iftakher Hossain
Md Iftakher Hossain - avatar
0
Thank you all for answering got the concept 👍
11th Jun 2020, 2:26 PM
Vaibhav Dadhich
Vaibhav Dadhich - avatar