NaN-trapping operators

!<= - Less than or equal to. If either operand is the value NaN prior to coercion, throw an exception.
!< - Less than. If either operand is the value NaN prior to coercion, throw an exception.
!>= - Greater than or equal to. If either operand is the value NaN prior to coercion, throw an exception.
!< - Greater than. If either operand is the value NaN prior to coercion, throw an exception.

Motivation: I have dealt with a frustrating bug where a comparison with NaN led to memory leaks. NaN semantics can convert an attribute access of an undefined property into a subtle memory leak.

I can imagine other useful semantics for less number-oriented applications. (Perhaps those would check for validity after coercion?) However, I don't have enough experience with those applications to suggest further semantics for these operators. Please reply to extend this idea with more semantics if you have a good idea.

1 Like

I would like to add that this is the current solution I use:

Object.defineProperty(Number.prototype, 'notNaN', { get: function () {
    if (Number.isNaN(this)) {
       throw new Error();
    } else return this;
}});
1 Like

Looks like unwrap() for me LOL