Last Updated: December 26, 2018
·
1.216K
· pedrochaves

Using bitwise-or to convert string to number

You can save a few bytes in your JavaScript code by using the | (bitwise-or) operator instead of parseInt.

var num = "123" | 0; // Returns 123

This code above is equivalent to writing

var num = parseInt("123", 10);

Just be careful about your hexadecimals and octals, this technique does saves some bytes but works kinda like parseInt without the second argument.