+ 3

[SOLVED] Why 'null >= 0' is TRUE?

Check the code please! I know from Algorithm that, if we compare null without undefine, the result will be always FALSE. So, 'null == 0' is FALSE. The second one very clear, null is converted into number which means 0. So 'null > 0' is easily FALSE. What about the third one 'null >= 0' is FALSE? Is that because the null converted into number and then compare to 0, am I right? Correct me please, if I'm wrong! https://sololearn.com/compiler-playground/cxTk3h6Ecpiw/?ref=app

30th Apr 2024, 6:21 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
3 ответов
+ 4
Long and deep explanation here: https://blog.campvanilla.com/javascript-the-curious-case-of-null-0-7b131644e274 Short: null >= 0 is true because null < 0 is false That's javascript weak typing for you. More unreasonable rules than you would ever need.
30th Apr 2024, 7:30 AM
Tibor Santa
Tibor Santa - avatar
+ 4
Solo Thanks for your concern
30th Apr 2024, 12:10 PM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar
+ 3
`нттp⁴⁰⁶ yes, you are absolutely right, there is a conversion of type to number. It is very easy to remember, operators: "<, >, <=, >=" – they are operators of arithmetic comparison, which already from the name it can be understood that they compare numeric values. The "==" operator is called the equality operator, which distinguishes it from the rest. Unfortunately, or fortunately (depending on how you look at it...😎), my security system does not allow me to follow the link of Tibor Santa, but I assume that it is written there in general terms and how correctly he noticed that all these subtleties of compiling an algorithm of comparisons, it is unlikely that we will ever they will be useful, especially since in fact no one knows the algorithm for creating the original JavaScript source, since it has not been published anywhere. To date, there are three algorithms, two of which are almost identical in their functionality. Thus, there is no one-size-fits-all solution.
30th Apr 2024, 10:30 AM
Solo
Solo - avatar