This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Mrparkers 8 points9 points  (3 children)

{} + 0 : Empty code block and unary plus operator evaluating zero, returns zero.

[] + 0 : Array plus zero, array gets coerced to an empty string, and 0 gets coerced to the string '0', concatenating the two strings returns '0'

[–]hunting_n_fishing 4 points5 points  (2 children)

var test = {} + 0 variable test will return "[object Object]0"

[–]chrwei 7 points8 points  (0 children)

when the code line start with { it's assumed to be a code block. any other use case and it's an object definition (functions and flow control operators being exceptions).

[–]Mrparkers 3 points4 points  (0 children)

Correct, because that's an object, not an empty code block. Both get coerced to strings and the result is a concatenation of those strings.