# JavaScript shortcuts using bitwise operators

Rico Sta. CruzMarch 20, 2015 Some common operations can be made shorter using bitwise operators. Here are some of my favorites.

### Rounding off a number

`Math.floor(3.5)`

can be written as `3.5|0`

. The Bitwise OR operator will make an integer out of the number, and this construct is in fact used in asm.js to denote an integer.

### Checking for -1

The Bitwise NOT operator will turn `-1`

into zero. This makes substring checks with `indexOf()`

a little shorter.