8000 Fix make _.isNumber(NaN) return false and update tests by Rishiyaduwanshi · Pull Request #5982 · lodash/lodash · GitHub
[go: up one dir, main page]

Skip to content

Fix make _.isNumber(NaN) return false and update tests #5982

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Rishiyaduwanshi
Copy link

📌 Fix: _.isNumber(NaN) now returns false as expected (Fixes #5981)

🐛 The Issue

In Lodash v4.17.21, the _.isNumber function incorrectly returns true for NaN. This is problematic in scenarios where consumers of the library want to distinguish valid numbers from NaN.

Reference: Issue #5981

✅ The Fix

The isNumber function has been updated to return false when the input is NaN. The logic now ensures that:

  • Primitive NaN values are filtered out.
  • Boxed NaN values (e.g., Object(NaN)) are also handled appropriately.
    function isNumber(value) {
      return (typeof value == 'number' && !Number.isNaN(value)) ||  
             (isObjectLike(value) && baseGetTag(value) == numberTag);
    }

🧪 Tests Updated

  • Updated test case: assert.strictEqual(_.isNumber(NaN), false);
  • Verified against full test suite using pnpm test.
  • All tests passing ✅

@Rishiyaduwanshi
Copy link
Author

Hi! Just following up on this PR. Let me know if any changes are needed. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

The issue that _.isNumber(NaN) returns true. VERSION 4.17.21
1 participant
0