+ 4

Why JavaScript return false in this case?

var a = 10; b = 20; c = 30; console.log( c > b > a) //false

22nd Jan 2020, 4:05 PM
Md. Faruk Hosen
Md. Faruk Hosen - avatar
4 Respostas
+ 13
Associativity for > operator in JS is left to right. c > b > a is evaluated as (c > b) > a (30 > 20) > 10 true > 10 JS converts true to 1 and executes comparison 1 > 10 false
22nd Jan 2020, 4:10 PM
Hatsy Rei
Hatsy Rei - avatar
+ 3
A similar question in C language. https://www.sololearn.com/Discuss/2140916/?ref=app
22nd Jan 2020, 4:14 PM
Avinesh
Avinesh - avatar
+ 1
Hatsy Rei i understand your explanation. I recently had a problem like this in python. Is there a way we can do this? I want a user to input an integer n, between 2 to 5 and output a string if the input is even. Tried doing this if n % 2 == 0 and 2 == n <= 5: print ("Not Weird") ..... Didn't work. I tried another way and got it. Sorry for the long story but is there a way we can write this an one expression instead of two?
23rd Jan 2020, 9:54 PM
Chidera Nwosu
Chidera Nwosu - avatar
0
thanks its clear now
22nd Jan 2020, 4:29 PM
Md. Faruk Hosen
Md. Faruk Hosen - avatar