Skip to content

Instantly share code, notes, and snippets.

@g-k
Last active December 14, 2015 04:19
Show Gist options
  • Save g-k/5027014 to your computer and use it in GitHub Desktop.
Save g-k/5027014 to your computer and use it in GitHub Desktop.
Mask Boxed JS number with valueOf
// 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