最終更新:2019-05-17 (金) 18:26:02 (6d)  

数値?
NaN はてなブックマークを見る
Top / NaN

Not a Number

JavaScript

  • NaN == NaN はfalse→isNaNで調べる
isNaN(NaN);       // true
isNaN(undefined); // true
isNaN({});        // true

isNaN(true);      // false
isNaN(null);      // false
isNaN(37);        // false

// strings
isNaN("37");      // false: "37" is converted to the number 37 which is not NaN
isNaN("37.37");   // false: "37.37" is converted to the number 37.37 which is not NaN
isNaN("");        // false: the empty string is converted to 0 which is not NaN
isNaN(" ");       // false: a string with spaces is converted to 0 which is not NaN

// This is a false positive and the reason why isNaN is not entirely reliable
isNaN("blabla")   // true: "blabla" is converted to a number. Parsing this as a number fails and returns NaN

C♯

関連