DEV Community

Discussion on: 5 JavaScript "tips" that might bite you back.

Collapse
 
moopet profile image
Ben Sinclair

Do people really do things like exploit bitwise operators as an alternative to rounding? In 2021? (I get to say that today!)

Collapse
 
mrwensveen profile image
Matthijs Wensveen

Not as an alternative to rounding, which is just wrong. But it's an extremely easy and fast way to cast your value to int. If you're doing fast graphics stuff, bitwise operations can be really useful.

Collapse
 
moopet profile image
Ben Sinclair

If you're in the sort of situation where that optimisation is important, then you're probably keenly aware of what you're doing. I'd never recommend this to anyone who wasn't already an expert.