Last active
December 25, 2015 12:13
-
-
Save mamoo/3078df0bf8fc59c91304 to your computer and use it in GitHub Desktop.
Javascript conversion to Integer using bitwise OR with zero
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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