Skip to content

Instantly share code, notes, and snippets.

@easierbycode
Created March 1, 2012 22:03
Show Gist options
  • Select an option

  • Save easierbycode/1953550 to your computer and use it in GitHub Desktop.

Select an option

Save easierbycode/1953550 to your computer and use it in GitHub Desktop.
object to primitive coersion
var foo = {
toString: function () {
return 5;
},
valueOf: function () {
return "foo";
}
};
alert(foo.toString() + 1); // 6 (bad!)
alert(foo + 1); // "foo1" (no good!)
alert(+foo); // NaN (the worst!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment