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

Clarify proper type casting for Numbers #524

Merged
merged 1 commit into from
Sep 25, 2015
Merged

Clarify proper type casting for Numbers #524

merged 1 commit into from
Sep 25, 2015

Conversation

DannyNemer
Copy link
Contributor

Clarifies when to use Number vs. parseInt for Number type casting, encouraging the proper usage of both.

Fixes: #523

Previously, at item 21.3, the guide read:

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);

Issue: It is unclear whether Number is acceptable because the guide only directly states to use parseInt despite the example for Number. Indeed, Number and parseInt are not interchangeable and should both be used properply.

@@ -1640,7 +1640,7 @@ Other Style Guides
const totalScore = String(this.reviewScore);
```

- [21.3](#21.3) <a name='21.3'></a> Use `parseInt` for Numbers and always with a radix for type casting.
- [21.3](#21.3) <a name='21.3'></a> Numbers: Use `Number` for type casting and `parseInt` with a radix for parsing.
Copy link
Collaborator

Choose a reason for hiding this comment

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

could this say parsing strings, and also continue to say always with a radix?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Clarifies when to use `Number` vs. `parseInt` for Number type casting.

Fixes: #523
@ljharb
Copy link
Collaborator

ljharb commented Sep 25, 2015

👍 this LGTM

ljharb added a commit that referenced this pull request Sep 25, 2015
Clarify proper type casting for Numbers
@ljharb ljharb merged commit d14e8b7 into airbnb:master Sep 25, 2015
@DannyNemer DannyNemer deleted the patch-1 branch September 25, 2015 14:23
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