LoginSignup
1
1

More than 5 years have passed since last update.

underscoreコードリーディング(isNaN)

Posted at

underscoreに詳しくないので、勉強半分でソースコードを読む。

利用するバージョン

underscore.js(v1.8.3)

isNaNとは

underscorejs.orgのisNaN

こんな説明。

_.isNaN(object)

Returns true if object is NaN.
Note: this is not the same as the native isNaN function, which will also return true for many other not-number values, such as undefined.

_.isNaN(NaN);
=> true
isNaN(undefined);
=> true
_.isNaN(undefined);
=> false

objectがNaNだった場合にtrueを返します。
注記:nativeのisNaN関数はundefinedなどのnot-numberな値だった場合にもtrueを返しますが、_.isNaNはそれとは挙動が違います。

underscore.isNaN

コード的にはこのあたり。

  // Is the given value `NaN`? (NaN is the only number which does not equal itself).
  _.isNaN = function(obj) {
    return _.isNumber(obj) && obj !== +obj;
  };

isNumberに合致するかつ、objが+objと合致しない場合にtrueを返します。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1