Skip to content

Commit 2d97594

Browse files
committed
Merge pull request airbnb#126 from Jabher/patch-1
32-bit integers and bitwise operators explained with example of issues
2 parents 8cfb740 + 3882949 commit 2d97594

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,6 @@
970970
```
971971
972972
- If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing.
973-
- **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but Bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109)
974973

975974
```javascript
976975
// good
@@ -982,6 +981,14 @@
982981
var val = inputValue >> 0;
983982
```
984983

984+
- **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but Bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647:
985+
986+
```javascript
987+
2147483647 >> 0 //=> 2147483647
988+
2147483648 >> 0 //=> -2147483648
989+
2147483649 >> 0 //=> -2147483647
990+
```
991+
985992
- Booleans:
986993

987994
```javascript

0 commit comments

Comments
 (0)