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

Possible typo at #21.3 #523

Closed
DannyNemer opened this issue Sep 25, 2015 · 2 comments
Closed

Possible typo at #21.3 #523

DannyNemer opened this issue Sep 25, 2015 · 2 comments

Comments

@DannyNemer
Copy link
Contributor

At item 21.3, the guide reads:

Use parseInt for Numbers and always with a radix for type casting.

However, the example displays:

// good
const val = Number(inputValue);

// good
const val = parseInt(inputValue, 10);

Question: Is the first of the above examples supposed to be // bad (not // good), or should the guide read "Use parseInt or Number for Numbers..."?

Thank you.

@ljharb
Copy link
Collaborator

ljharb commented Sep 25, 2015

parseInt is only meant to take a String, and will also discard non-number characters - ie, parseInt('3a', 10) will be 3, but Number('3a') will be NaN - so they're slightly different there. Number is also the proper way to coerce non-string values to numbers.

My guess is that the wording should be changed to encourage proper usage of both.

@DannyNemer
Copy link
Contributor Author

Thank you for your response. I agree and opened a pull request to address this: #524.

gilbox pushed a commit to gilbox/javascript that referenced this issue Mar 21, 2016
Clarifies when to use `Number` vs. `parseInt` for Number type casting.

Fixes: airbnb#523
jaylaw81 pushed a commit to appirio-digital/ads-best-practices that referenced this issue Sep 19, 2017
Clarifies when to use `Number` vs. `parseInt` for Number type casting.

Fixes: airbnb#523
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

No branches or pull requests

2 participants