Skip to content

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 ✅

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants