Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect explanation #275

Open
AbdSat opened this issue Aug 12, 2022 · 0 comments
Open

Incorrect explanation #275

AbdSat opened this issue Aug 12, 2022 · 0 comments

Comments

@AbdSat
Copy link

AbdSat commented Aug 12, 2022

However, the >= operator in fact works in a very different way, which is basically to take the opposite of the < operator

That's not ture, >= and <= operators just convert both sides to numbers if they have different types and that's why null >= 0 returns true because 0 == 0 is true.

You can test that withNaN and will return false :

NaN == 0 // false
NaN > 0 // false

// But ...
NaN >= 0 // false

You can see that NaN < 0 returns false and >= operator doesn't return the opposite.

So >= and <= operators are just shorthands :
x >= yx > y || x == y
x <= yx < y || x == y
and if x and y have different types they will be converted to numbers before comparing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant