0
    ///if the feature/method 'is' is not present on Object object
    if (!Object.is) {
    //define it
      Object.is = function(x, y) {
      //check wether they are equal without any conversion
        if (x === y) { 
        //x not equal to zero 
         //or (example  is(4,4) ) 1 / 4 (0.25)   === 1 / 4  (0.25)
          return x !== 0 || 1 / x === 1 / y;
        } else {
          // here is the big problem :(
          // I know the below part deals with NaN, but what does it exactly mean?
          return x !== x && y !== y;
        }
      };
    }

source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is

  • Try to do `NaN === NaN` and see what's the output ;) A better way to do it would be: `Number.isNaN(x)` – Nir Alfasi Jan 22 '20 at 21:52
  • I guess it's a sketchy way to check for `NaN`, just as you already suggest. Not foolproof, but unless someone tries to deliberately fool it, should work. – ASDFGerte Jan 22 '20 at 21:52
  • @ASDFGerte Actually, it is *the* foolproof way, as nobody can fool the `!==` operator. The global `isNaN` function or similar could be overwritten though. – Bergi Jan 22 '20 at 21:55
  • You can e.g. load properties into the variable environment, that self-mutate on access. As said, it's far fetched, but `NaN` isn't the only possibility for `x !== x` to yield true. – ASDFGerte Jan 22 '20 at 21:57
  • 1
    @ASDFGerte You cannot load anything into the variable environment of the `Object.is` function as implemented above, since it defines `x` as a local variable. (Apart from that, yes, I'm aware of [this question](https://stackoverflow.com/q/48270127/1048572)) – Bergi Jan 22 '20 at 22:00
  • You are right, i forgot these are function arguments. Now i'll probably spend an hour, thinking about whether there isn't some abstruse language feature to trick it anyways. – ASDFGerte Jan 22 '20 at 22:18

0 Answers0