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.
Written by Pedro Chaves
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Optimization
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#