608
you are viewing a single comment's thread
view the rest of the comments
[-] hperrin@lemmy.ca 1 points 5 days ago* (last edited 5 days ago)

Ok, except I did predict it. It turns them both into strings and gives you “12”. I checked it. But I didn’t mean predictable as in, you inherently know what it’s going to do, I meant predictable as in, it will follow the same badic rules in each circumstance.

So, should web pages be prone to crashing if everything isn’t perfect? I don’t know if you remember XHTML, but that was basically what happened with that. You have a “div” within a “p”? Page crashed. You have an unclosed “span”? Page crashed. XHTML was abandoned because is constantly broke the web.

Web technologies are supposed to be resilient, so throwing TypeError is the last resort for something that absolutely cannot work, like trying to add to a Symbol. Since nothing from the user is ever a Symbol (there’s no input that can give it, and it can’t be stored in JSON), it’s acceptable to throw a TypeError there.

JavaScript is meant to be fast and resilient. Its type conversions make sense when you consider those goals.

[-] bobo@lemmy.ml 2 points 5 days ago

Ok, except I did predict it. It turns them both into strings and gives you “12”. I checked it.

I would assume [1] + [2] would give you either 0 or 2, but maybe "12".

I can totally predict the future like that. Tomorrow it might rain, it might not, or it might snow. Want me to predict your future for a small donation? Here's a small teaser: tomorrow you might or might not eat breakfast.

My mystical powers lay the creation bare before me, all is predictable!

[-] hperrin@lemmy.ca 1 points 5 days ago

Here’s my thought process: plus is for numbers and strings, so it’s gonna convert the arrays to either numbers or strings. If it converts them to 0, the answer is 0, if it converts them to 1, the answer is 2, if it converts them to strings, the answer is “12”.

You know what I didn’t say? [1,2]. Because plus is not for array concatenation. The question is meant to make you think you’ll get [1,2], because why else would you use plus on arrays?

In a language that uses plus for concatenation, you’ll see that kind of code all over, and know what you’ll get. But you never see that in JavaScript, because that’s not how we concatenate arrays.

[-] FishFace@piefed.social 1 points 5 days ago

Getting it on the third guess is not the brag you seem to think, and I'm still not engaging with you on the rest.

[-] hperrin@lemmy.ca 0 points 5 days ago

I’m sorry I didn’t think it was [1,2].

this post was submitted on 24 Nov 2025
608 points (89.2% liked)

Programmer Humor

27542 readers
437 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS