-1

I am stuck with this peculiar scenario mentioned below. Could someone please explain to me what's the reason for the following behavior.

Why is Infinity - Infinity results NaN, but NaN === (Infinity-Infinity) results false ?

Anantha Raju C
  • 1,780
  • 12
  • 25
  • 35
manju4ever
  • 325
  • 1
  • 13
  • 6
    because `NaN !== NaN`. – Cristian Lupascu Sep 27 '15 at 10:48
  • Infinity is sometimes defined as the ability to define a subset that doesn't include all elements but is also infinite. Substracting infinity from infinity doesn't give a set outcome and is therefor not a number. That said it's impossible to validate wether 2 things are equal if all you know is that both are not numbers. – DrunkWolf Sep 27 '15 at 10:56

1 Answers1

6

The answer lies in the full form of NaN.
NaN stands for Not a Number.
Hence, if something is not a number, it cannot be compared or checked for equality.

Going mathematically,

Infinity - Infinity = NaN   (1)

NaN == Infinity - Infinity  (2)

Here in (1) NaN holds a value that signifies the result is not quantifiable.

And in (2) you are checking the equality of 2 entities that are not quantifiable.

Hope that makes sense.

P.S. I know string values can be compared, but that is not the case with NaN.

akshaynagpal
  • 2,965
  • 30
  • 32