Skip to content
Advertisements

Number.isNaN()

Why Number.isNaN ?

The Number.isNaN () method checks whether the value to be checked is a number. is different from the isNumber () method. Returns the value of “false” if the value to be checked in the Number.isNaN () method. Returns “true” if the number to be checked is not a number.

Number.isNaN () is different from global isNaN (). The global isNaN () function converts the tested value to a Number, then tests it. Number.isNaN () does not convert values to a Number and does not return true for any value that is not of Number.

Syntax:

Number.isNaN(value)

  • value (required): It is the value which is to be tested for NaN.

JavaScript Number.isNaN Example

Example

        let val1 = Number.isNaN(1234);
        let val2 = Number.isNaN(1.55);
        let val3 = Number.isNaN(-8.99);
        let val4 = Number.isNaN(0);
        let val5 = Number.isNaN(null);
        let val6 = Number.isNaN("394");
        let val7 = Number.isNaN("truecodes.org");
        let val8 = Number.isNaN(2000 / 1000);
        let val9 = Number.isNaN(Infinity);
        let val10 = Number.isNaN(-Infinity);
        let val11 = Number.isNaN(0 / 0);
        let val12 = Number.isNaN(function () { });
        let val13 = Number.isNaN(2019 / 02 / 03);

output:

false
false
false
false
false
false
false
false
false
false
true
false
false


Polyfill

Number.isNaN = Number.isNaN || function(value) {     
    return value !== value;
}

Source:


Browser Support

Chrome25
Edgeyes
Firefox15
Internet Explorerno
Opera9
Safariyes
Android webviewyes
Chrome for Androidyes
Edge mobileyes
Firefox for Android15
Opera Androidyes
Advertisements

1 Comment »

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: