3

I'm not able to establish if my javascript variable is a number or not.

Here's what I have:

alert('variable startDateB: ' + startDateB);

Results:

variable startDateB: NaN

In the very next line I have:

alert('typeof startDateB: '  + typeof(startDateB));

Results:

typeof startDateB: number

My end goal is to compare this date with other dates, but I don't know whether a conversion is necessary since I appear to be getting mixed information about the variable's data type.

Any help is greatly appreciated!

Thanks!

Josh
  • 105
  • 1
  • 9

1 Answers1

3

By definition, NaN is the return value from operations which have an undefined numerical result.

Aside from being part of the global object, it is also part of the Number object: Number.NaN.

This is why you are seeing the behavior you describe. NaN is part of the Number object.

It is still a numeric data type, but it is undefined as a real number.

Patrick
  • 5,526
  • 14
  • 64
  • 101