Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Allowing assert.deepEqual to check NaN values for equality #7920

Closed
wants to merge 2 commits into from
Closed

Allowing assert.deepEqual to check NaN values for equality #7920

wants to merge 2 commits into from

Conversation

kode4food
Copy link

An Object may have NaN as one of its property values. NaN doesn't compare directly to itself, so isNaN() must be used instead.

An Object may have NaN as one of its property values.  NaN doesn't compare directly to itself, so isNaN() must be used instead.
@Fishrock123
Copy link

I think this would be candidate for a deepStrictEqual ala #7161

@kode4food
Copy link
Author

@Fishrock123 if we were calling this strict, could we really say NaN === NaN since we don't know what the NaN truly represents? I was thinking it leaned more toward the loose (==) definition. The use case that served as the catalyst for this was comparing the deserialized version of an Object serialized into a binary format I devised. So technically, I actually want strict comparison. That said, either way could work for me.

// 7.4 If the expected value is NaN, we need to perform this comparison
// using isNaN(), as the next case will not catch the condition.
} else if (util.isNumber(expected) && isNaN(expected)) {
return isNaN(actual);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're looking for Number.isNaN().

Corrected
@kode4food kode4food closed this Jul 22, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants