Skip to content
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

Fix checking a symbol is a number #2

Closed
wants to merge 1 commit into from

Conversation

kovetskiy
Copy link

@kovetskiy kovetskiy commented Feb 26, 2021

Number.isFinite() is different from the global isFinite() function. The global isFinite() function converts the tested value to a Number, then tests it.

Number.isFinite() does not convert the values to a Number, and will not return true for any value that is not of the type Number.

Well, it turns out, the library never really worked.

const is = (n) => !Number.isNaN(parseFloat(n)) && Number.isFinite(n);

is(1)
true

is('1')
false

is('1.0')
false
n='1'; console.log('Number.isFinite', Number.isFinite(n), 'isFinite', isFinite(n))
Number.isFinite false isFinite true

Number.isFinite() is different from the global isFinite() function. The global isFinite() function converts the tested value to a Number, then tests it.

Number.isFinite() does not convert the values to a Number, and will not return true for any value that is not of the type Number.
@zizzle6717
Copy link

Thanks for finding this bug. I've fixed this by converting the string to a number before calling Number.isFinite() on it and published a new version. I'd prefer to use Number.isFinite as it is best practice and makes the linter happy :)

@zizzle6717 zizzle6717 closed this Mar 2, 2021
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.

2 participants