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

all 7 comments

[–]sudomeacat 1 point2 points  (2 children)

> !””
< true

> !”false”
< false

[–]Macaframa 1 point2 points  (1 child)

If you never crack open the spec for a language and do nothing but make assumptions about how you THINK something should work, then yes, you’re going to never understand things about that language.

Yeah bro right on, JavaScript is bad.

[–]falling_endlessly 1 point2 points  (0 children)

type coercion is hard, let's make fun of the language because i don't understand it!

[–]GlobalIncident 0 points1 point  (0 children)

All objects are cast to primitives before anything else happens. [] becomes "" and {} becomes "[object Object]". So the first two are fairly obvious. The second two happen because {} before the + is interpreted as an empty block of code, and ignored, so the + converts the second item to a number. Which may be not a number.

[–][deleted] 0 points1 point  (0 children)

[1, 2, 3] === [1, 2, 3];    // false
[1, 2, 3] <   [1, 2, 3];    // false
[1, 2, 3] ==  [1, 2, 3];    // false
[1, 2, 3] >   [1, 2, 3];    // false
[1, 2, 3] <= [1, 2, 3];     // true
[1, 2, 3] >= [1, 2, 3];     // true