Last active
December 14, 2015 04:19
-
-
Save g-k/5027014 to your computer and use it in GitHub Desktop.
Mask Boxed JS number with valueOf
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
// Boxed JS number with valueOf method can mask its value. | |
> three = new Number(3); // Box 3 as a Number object | |
Number {} | |
> three.valueOf = function () { return 1; }; | |
function () { return 1; } | |
> 2 + three | |
3 | |
> 2 + 3 | |
5 | |
> 2 + +three.toString() | |
5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment