Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
Inconsistent behavior of 'greater than or equal' and 'equality' operators regarding 'undefined'

If the equality (strict or not) operator returns true for undefined...

console.log(undefined == undefined)

...why does the greater or equal than operator returns false?

console.log(undefined >= undefined)

The MDN page says that the operands are compared using the Abstract Relational Comparison, but that refers to greater than (or less than) part. Thus, it seems to me that the greater than or equal should provide the same algorithm for equality, isn't that correct?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Thus, it seems to me that the greater than or equal should provide the same algorithm for equality, isn't that correct?

No, that algorithm is not involved here. The spec defines the evaluation of >= as

  1. Let lref be the result of evaluating RelationalExpression.
  2. Let lval be ? GetValue(lref).
  3. Let rref be the result of evaluating ShiftExpression.
  4. Let rval be ? GetValue(rref).
  5. Let r be ? IsLessThan(lval, rval, true).
  6. If r is true or undefined, return false. Otherwise, return true.

So the only algorithm involved is IsLessThan, which will convert its operands to numbers if they are not already numbers (or strings).

undefined gets converted to NaN and Number::lessThan returns undefined if any operand is NaN, which, according to step 6 above results in false.

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!