Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
kpenc21298yOne of the things i don't like in JavaScript. In Python for example, you will get an exception if you try this, because it is strongly typed even though it's dynamic.
-
I can see why this is. Tho to me, this would be better and probably more consistent like this:
2 + 2 => 4
2 - 2 => 0
'2' + '2' => '22'
'2' - '2' => '' //empty string
'2' + 2 => '22'
'2' - 2 => '' //empty string
2 + '2' => 4
2 - '2' => 0
Where whatever the first type is, the result will be of that type. This would mean that for strings, minus should be a "de-concatination" or something.
Edit: tho of course, a type mismatch error is the Real best way to go. -
@DLMousey I was reading the rant and the comments mildly entertained then I came across your comment and literally laughed out loud.
-
stuqshwk2278yWtf. And web-people say C++ sucks because of pointers ... I have types. I have the best types! JS sooo depressing! Baaaad!!!
Ok, you could define an operator, that does the JS obstruction of logic for you ...
std::string operator+(const std::string& a, const int b){ return a + std::to_string(b);}
... and all the other crazy people rules ... -
If you are subtracting a string, you've fucked up enough you deserve that behavior.
-
@hube that happens when an old guy stays in the past. We had to learn turbo Pascal first. I hated it an frankly cared so little about it that during exams I let somebody else code the stuff for me 😁 after that we started with C and that's when I really woke up because I knew it already. I think the best languages for programming beginners are either Ruby or Python.
'2' + 2 => '22'
'2' - 2 => 0
Js devs will understand
undefined
wtfisthis
javascript