~ actually does a 2s complement on the individual bits. In any language except JavaScript doing bit operations like that would be a billion times faster than doing arithmetic operations. JavaScript is extremely slow at bit operations so any other way would probably be faster than using bit operators (which is why you don’t often see them used in JavaScript). Generally only programming gurus who are also JavaScript newbies would consider them.