-
Notifications
You must be signed in to change notification settings - Fork 26.5k
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
Preferred method of integer casting? #18
Comments
I always do see Numbers: https://github.com/airbnb/javascript#type-coercion |
Here's a jsPerf Coercion vs. Casting vs. Bitshift Looks like casting with |
parseInt looks good. |
I didn't expect bitshifting to be so much slower than I always use |
If we go with // Bad
parseInt('123');
// Good
parseInt('123', 10); |
Took a look with other browsers- bitshift is drastically better on FF and IE. Not sure if buggy test result. |
Woah, what's Webkit got against bitshift? I vote we go with But it should be allowed to do bitshifting if you need to performance boost on lots of strings to ints. Maybe just leave a comment why you think you need to bitshift over being explicit? |
👍 for Also 👍 for including a radix when calling |
👍 for
Fair, if you have profiling that proves |
It's a small thing, but we should probably be consistent here, too. What's the best way to cast to integers? I have the habit of bitshifting by 0
"15" >> 0
; it's one of the more performant ways to do it, and it's concise, but it also isn't super obvious.The text was updated successfully, but these errors were encountered: