this post was submitted on 04 Jun 2025
1012 points (98.6% liked)
Programmer Humor
23849 readers
2280 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
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
It's not nonsensical, implicit type coercion is a feature of JavaScript, it's perfectly logical and predictable.
JavaScript is a filthy beast, it's not the right tool for every job, but it's not nonsensical.
When you follow a string with a
+
, it concatenates it with the next value (converted to string if needed). This makes sense, and it's a very standard convention in most languages.Applying arithmetic to a string would be nonsensical, which they don't do.
You are entitled to your opinion. implicit conversion to string is not a feature in most languages for good reasons.
Sure. And you're entitled to yours. But words have meaning and this isn't MY OPINION, it's objective reality. It follows strict rules for predictable output, it is not nonsensical.
You're entitled to think it's nonsense, and you'd be wrong. You don't have to like implicit type coercion, but it's popular and in many languages for good reason...
'5' - 1 → 4
'5' + 1 → 6
'5' + 1 → 6
$(( '5' + 1 )) → 6
"5" + 1 → 6
"5" + 1 → 6
'5' + 1 → 54
(ASCII math)'5' + 1 → 6
'5' + 1 → 6
'5' - 1 → 4
"5" + 1 → 6
'5' + 1 → 6
'5' + 1 → 6
'5' + 1 → 6
'5' + 1 → 6
'5' - 1 → 4
'5' - 1 → 4
"5" + 1 → 6
(5) 1 add → 6
I think JavaScript is filthy, I'm at home with C#, but I understand and don't fear ITC.
Also, you contradicted yourself just then and there. Not a single of your examples does string concatenation for these types. It's only JS
So, I think probably everyone in the thread is "correct", but you are actually talking past one another.
I think the JS behavior is a bad design choice, but it is well documented and consistent across implementations.
Read the thread again, it seems you slipped somewhere. This was all about the claim that implicit conversion to string somehow could make sense.
C# is filthy. But it explains where you got your warped idea of righteousness.