re: JavaScript Quiz VIEW POST

VIEW FULL DISCUSSION
 

I scored 4 out of 6. But if I wasn't able to run them as I went, it would be much lower.

Also, I feel like you should add "2"+4 right after 2+"4", b/c I was definitely wondering if the casting decision was based on which one was first. Eg in Ruby, + is a method call, so 2+"4" would be calling Integer#+ and "2"+4 would be calling String#+, thus the ordering implies different behaviour, even though + in math is commutative. I know that's not how JS works, but it means that I would at least be entertaining the possibility of non-commutativity.

null === undefined
// expected: false
// actual:   false
// score:    1/1

null == undefined
// expected: false... but less confidently :/
// actual:   true
// score:    1/2

2+"4"
// expected: Jesus >.< uhm... 6? If not 6, than 24, pretty sure
//           one of them gets cast, just not sure which.
// actual:   fuuuuuuck, 24 >.<
// score:    1/3

2-"3"
// expected: Based on the above, I'm really hoping it's -1
// actual:   -1
// score:    2/4

""+2
// expected: Oh fuck. uhhhh. maybe it comes in as zero, or maybe
//           it gets treated like a character string instead of
//           a number string, which maybe casts the 2 to a string
//           ...wait, yeah, it's definitely "2"!
// actual:   "2"
// score:    3/5

+"2"
// expected: Probably 2, right? I'd expect it to cast the "2" to
//           a number and then make it "positive" or something.
// actual:   2
// score:    4/6
code of conduct - report abuse