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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#