Huh? I can't say about "most", but most that I am aware of or used, no.
Also, even if that was true. That's still very error-prone thing, even if everyone else does it. While I don't agree that JS is really bad language overall, this shit is bad.
I mean, I've only done Ruby and C# in my professional life, but they both do it and I know from school that Java does it and I think python does too? I don't know, those could be outliers and be the only ones who does this.
I don’t think any of the languages you’ve named do this to the same extent as JavaScript. I could be wrong, but if I recall correctly Java and C# will coerce to a string if you’re concatenating, but will still throw an error if you’re passing to a function that expects a string (like this case in JavaScript). I don’t think Python implicitly coerces anywhere (outside of functions like print and explicit string interpolation). I’m not sure about Ruby, but I think it only coerces certain string-like types in certain contexts.
Old JavaScript would coerce everywhere imaginable because it really didn’t want to throw errors.
The languages that maybe do similar with I can think of are Perl and Php.
No. Some old bad ones do. Modern ones only do in specific contexts where string interpolation is explicitly indicated or the result is immediately meant for displaying to a user. Automatically converting when you call print makes sense since the functions role is converting from structured data to human output. Creating a regex matcher is not a case where that makes sense.
View all comments
Show parent comment
1
u/Eva-Rosalene Mar 21 '24
Mostly this one.