isNaN.js 825 B

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