node-deep-equal
node-deep-equal copied to clipboard
Equivalent objects with NaN values are treated as not equal
Node version: 15.14.0 deep-equal version: 2.0.5
Test:
❯ node
Welcome to Node.js v15.14.0.
Type ".help" for more information.
> const deepEqual = require('deep-equal');
undefined
> deepEqual({ a: 123, b: NaN }, { a: 123, b: NaN })
false
>
I was expecting deep-equal to return true.
Node's assert.deepEqual says the above objects are equal:
> const assert = require('assert');
undefined
> assert.deepEqual({ a: 123, b: NaN }, { a: 123, b: NaN })
undefined
And this NaN unit test seems to assert that it returns true (?)
Is returning false the expected behavior?
It depends on which node version you're checking. In node < 14, that assert example throws.
It would be a breaking change for deep-equal to make the same change; I noted this in 93679546.
In other words, in v3, this will change, but for now it's stuck with the node < 14 semantics.
@ljharb Ah, ok. Thanks!
Enabling the strict option makes it work like Node 14's assert.deepEqual for NaN values, so I'll just run it with that option.
Right, it’s only loose equality where this applies.