11

I get this error in IE 11:

Object doesn't support property or method isNaN

JavaScript

jQuery(document).ready(function($) {
    var $total = $('#total'),
    $value = $('.value');
    $firstName = $('#firstname');
    $lastName = $('#lastname');
    $tour = $('#tour');
    $pledge = $('#pledge');
    $currency = $('#currency');
    $distance = $('#distance');
    $riders = $('#riders');

    $(':input').on('input change', function(e) {
        var total = 1;
        $value.each(function(index, elem) {
            if(!Number.isNaN(parseFloat(this.value)))
                total = total * parseFloat(this.value);
        });
        $total.val(total/10);

        $('#pledgefirstname').text($firstName.val());
        $('#pledgelastname').text($lastName.val());
        $('#pledgetour').text($tour.val());
        $('#pledgepledge').text($pledge.val());
        $('#pledgecurrency').text($currency.val());
        $('#pledgecurrency2').text($currency.val());
        $('#pledgecurrency3').text($currency.val());
        $('#pledgecurrency4').text($currency.val());
        $('#pledgetotal').text($total.val());
        $('#pledgetotal2').text($total.val());
        $('#pledgedistance').text($distance.val());
        $('#pledgeriders').text($riders.val());
    });
});
14
  • 6
    Just use a standalone isNaN method without calling it from Number object: if (isNaN(...)).
    – VisioN
    Commented Mar 20, 2014 at 15:58
  • 1
    Well, don't mix up window.isNaN and Number.isNaN(). I think the latter is an EcmaScript 6 feature.
    – Johan
    Commented Mar 20, 2014 at 15:59
  • 1
    OK thanks. What do you mean by that exactly? Commented Mar 20, 2014 at 15:59
  • see why: kangax.github.io/es5-compat-table/es6/#Number.isNaN
    – A. Wolff
    Commented Mar 20, 2014 at 15:59
  • 1
    Number.isNaN is a very new and still experimental feature of the next JavaScript spec. It is not supported at all in IE. You've likely confused it with the global isNaN function, which has support in all browsers.
    – ajp15243
    Commented Mar 20, 2014 at 15:59

3 Answers 3

13

Number.isNaN

This is an experimental technology, part of the Harmony (EcmaScript 6) proposal. Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.

It is still not supported by most of the browsers (including IE11).

You should use a standard isNaN method instead:

if (isNaN( parseFloat(this.value) )) { ... }
13
  • It is, in fact, not supported in any version of IE.
    – ajp15243
    Commented Mar 20, 2014 at 16:02
  • 2
    That would seem to be implied. Commented Mar 20, 2014 at 16:02
  • Can you help me with the implementation of your solution? I'm not sure how to translate it. What goes in the curly brackets? Commented Mar 20, 2014 at 16:04
  • @square_eyes: Yikes dude, I think you're really over-thinking this. Commented Mar 20, 2014 at 16:05
  • 1
    OK fixed it thanks @cookiemonster for the chat. I dropped the !, silly me. Commented Mar 20, 2014 at 16:38
6

If you are using ES6 with Babel in React. You can do like this:

// pollyfills for older browsers
// core-js v2.x.x:
import 'core-js/es6/number'; 
// core-js v3.x.x:
import 'core-js/es/number'; 

Add dependencies in package.json for

"dependencies": {
    "core-js": "^2.5.5",
  }
3

I had a similar problem except it was coming from React after it compiled, bundled, and minified. To solve this, I redefined the Number.isNaN:

if (!Number.isNaN) {
  Object.defineProperty(Number, 'isNaN', {
    value: function(value) {     
      return value !== value;
    }
  });
}
1
  • shoud be if (!Number.isNaN) { instead if (!Number.isNan) {
    – Seven
    Commented Jan 13, 2021 at 13:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.