Bellash
Bellash

Reputation: 8184

Numbers having parseInt value = NaN in JavaScript

   typeof 2; //number
   typeof "2"; //string
   parseInt("2");//2
   typeof Infinity; //number
   parseInt(Infinity);//NaN
   typeof NaN; //number
   parseInt(NaN);//NaN

are there other Number elements whose parseInt value is NaN? If yes, list/describe them please

UPDATES: What doesn't make sense in JavaScript is isNaN(NaN) returns true while typeof NaN returns number

Upvotes: 0

Views: 132

Answers (2)

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

parseInt works on strings, so whatever you give it, it will be converted to a string.

Infinity => "Infinity" => NaN

But since you asked...

parseInt(-Infinity); // NaN

Upvotes: 3

algorhythm
algorhythm

Reputation: 8728

Infinity is a Number, try

isNaN(Infinity); // gives 'false' so it is a Number

But first parameter of parseInt is a string and Infinity already is a Number... so you can't parse it.

Upvotes: 0

Related Questions