Вопрос по javascript – Как определить, является ли значение NaN без использования isNaN, которое имеет ложные срабатывания? [Дубликат]

5

This question already has an answer here:

Error: User Rate Limit ExceededNaNError: User Rate Limit ExceededisNaNError: User Rate Limit Exceeded

Error: User Rate Limit Exceeded Rocket Hazmat
Error: User Rate Limit Exceeded asawyer
Error: User Rate Limit ExceededisNaNError: User Rate Limit Exceeded JaredPar
Error: User Rate Limit Exceeded Marc B
Error: User Rate Limit ExceededisNaNError: User Rate Limit Exceededes5.github.com/#x15.1.2.4Error: User Rate Limit Exceeded Rocket Hazmat

Ваш Ответ

2   ответа
1

Error: User Rate Limit Exceeded

var x = 'value';
var is_NaN = +x - x !== 0; // The + is actually not needed, but added to show
                           // that a number conversion is made.
Error: User Rate Limit Exceededx = Infinity?
Error: User Rate Limit Exceeded:)
Error: User Rate Limit ExceededisNaN(Infinity)Error: User Rate Limit ExceededfalseError: User Rate Limit Exceededreal numberError: User Rate Limit Exceeded
Error: User Rate Limit ExceededInfinity-InfinityError: User Rate Limit ExceededNaNError: User Rate Limit Exceeded
7

Error: User Rate Limit ExceededError: User Rate Limit ExceededError: User Rate Limit ExceededObject.is:

return Object.is(obj, NaN);

Error: User Rate Limit ExceededError: User Rate Limit Exceeded:

// Is the given value `NaN`?
_.isNaN = function(obj) {
  // `NaN` is the only value for which `===` is not reflexive.
  return obj !== obj;
};

Error: User Rate Limit Exceeded

Note: this is not the same as the native isNaN function, which will also return true if the variable is undefined.

isNaN('0') === falseError: User Rate Limit Exceeded_.isNaN('0')Error: User Rate Limit Exceeded
Error: User Rate Limit ExceededisNaNError: User Rate Limit Exceeded
isNaN('as')Error: User Rate Limit ExceededtrueError: User Rate Limit Exceeded_.isNaN('as')Error: User Rate Limit Exceededfalse.
Error: User Rate Limit ExceedednecessaryError: User Rate Limit ExceededusefulError: User Rate Limit ExceededNaNError: User Rate Limit Exceededundefined, "Hello World"Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded

Похожие вопросы