isNaN.js 911 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. var isNumber = require('./isNumber');
  2. /**
  3. * Checks if `value` is `NaN`.
  4. *
  5. * **Note:** This method is based on
  6. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  7. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  8. * `undefined` and other non-number values.
  9. *
  10. * @static
  11. * @memberOf _
  12. * @since 0.1.0
  13. * @category Lang
  14. * @param {*} value The value to check.
  15. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  16. * @example
  17. *
  18. * _.isNaN(NaN);
  19. * // => true
  20. *
  21. * _.isNaN(new Number(NaN));
  22. * // => true
  23. *
  24. * isNaN(undefined);
  25. * // => true
  26. *
  27. * _.isNaN(undefined);
  28. * // => false
  29. */
  30. function isNaN(value) {
  31. // An `NaN` primitive is the only value that is not equal to itself.
  32. // Perform the `toStringTag` check first to avoid errors with some
  33. // ActiveX objects in IE.
  34. return isNumber(value) && value != +value;
  35. }
  36. module.exports = isNaN;