Skip to content

Instantly share code, notes, and snippets.

@mamoo
Last active December 25, 2015 12:13
Show Gist options
  • Select an option

  • Save mamoo/3078df0bf8fc59c91304 to your computer and use it in GitHub Desktop.

Select an option

Save mamoo/3078df0bf8fc59c91304 to your computer and use it in GitHub Desktop.
Javascript conversion to Integer using bitwise OR with zero
/* Bitwise operators convert their operands to integers and give integer results.
* This means that a bitwise OR with zero, an otherwise useless operation, converts a value to an integer.
* Credits: http://en.wikipedia.org/wiki/Asm.js#Examples
*/
var notANumber = "5";
var aNumber = notANumber|0;
console.log(typeof aNumber);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment