Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does false == (x > y) work?

Tags:

javascript

I read this in a book and was just wondering how it works and if you would ever do something like that and for what reason you would do that. I understand you could return (x>y) but why would you do false == (x > y)?

like image 544
William James Avatar asked Dec 15 '22 13:12

William James


1 Answers

It's just a more verbose way of writing

x <= y

The result of x > y is evaluated and compared to false. Since the result of x > y is boolean, that's the same as writing

!(x > y)  // an == true is implied here if you don't add it yourself

which of course is the same as writing

x <= y
like image 80
Jon Avatar answered Dec 21 '22 23:12

Jon