Skip to content

Instantly share code, notes, and snippets.

@bcherry
Created November 3, 2011 03:15
Show Gist options
  • Save bcherry/1335683 to your computer and use it in GitHub Desktop.
Save bcherry/1335683 to your computer and use it in GitHub Desktop.
Also not that `a + "a"` is "3a" (and "a3" the other way around)
I'm pretty certain it's because `typeof a === "object"` and `typeof "a" === "string"`.
The `+` operator calls `toPrimitive` on each operand, but since the literal strings
are already primitives, no further action is taken. It's only when they are
objects that it delegates to `[[DefaultValue]]` which ends up calling its `valueOf` method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment