People that try to do mathematical operations with strings blaming the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense because they realized it would be used by people that have no idea what they are doing. Clearly they were right.
the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense…
…itself makes no sense. It is wrong and bad that Javascript was ever designed that way in the first place.
It was never intended to run full applications but only the small business scripts and hobbyist homepage stuff that were the thing in the 90s, across inconsistent browsers that were a jungle of hit and miss behaviour where it was preferred that menus keep working even if the mouse effect was not. Anything of scale was expected to be done in Java. Dynamic web pages did not exist and as anything not static was generated server side into a static html file to be rendered on the client.
Anyway, back then it wasn’t considered the job of the programming language to hold the hand of the aspiring developer as it is common today. It’s not a bad thing that IDE and even compilers and preprocessors try to help you write better code today, but then it simply didn’t exist.
JavaScript is from a different time and because it has the hard requirement or backwards compatibility there is no changing it and has not been for thirty years except to add stuff to it.
I think it’s just silly to ask the past to keep up with the present. Bad code is not the fault of the language regardless, even though junior devs and even seasoned ones like to think so to protect their ego. I think it is better to accept it, learn from it and roll with it because every single platform and language has their weird quirks anyway.
Signed, old dude that learned programming in 8 bit BASIC and 6502 machine code without an assembler, where code bad enough would freeze your machine that required a cold boot and starting over from your last save that you didn’t do.
Executing after undefined behavior is arguably worse than terminating with an exception. A terminated script can’t leak data or wreak havoc in other ways.
To start off… Using arithmetic operators on strings in combination with integers is a pure skill issue. Let’s disregard this.
If you were to use + where one part is a string, it’s natural to assume a string appending is desired since + is commonly used as a function for this. On the other hand, - is never used for any string operation. Therefore, it’s safe to assume that it relates to actual artihmetics and any strings should therefore be converted to numerical values.
This is an issue with untyped languages. If you don’t like it, use typescript. End of story.
Instead of trying to make it work, javascript could just say “error.” Being untyped doesn’t mean you can’t have error messages.
This is fair enough from an idealistic view. In practice, you don’t want your entire website to shit itself because of a potentially insignificant error.
In practice runtime errors are a bitch to find and fix.
Fair enough. This is why people prefer typescript
I’d rather have my website shit itself than have silent difficult to find errors.
Use typescript
Look! I bought this for free on capybaras website, there’s a glitch!
capybara: at least it didn’t throw an error.
/ jk 😁
Use typescript if you’re paranoid about this
Javascript is a dogshit language that everyone is stuck with. The best that we can hope for is the likes of typescript take the edge off of it. Even though it’s like smearing marzipan over a turd. At least it’s ok if you don’t take a deep bite.
JS should have never leaved the Browser side. Now you can use this thing for Backend and is just awful
Heck, I need to learn some new languages apparently. Here I was expecting an angry "CS0029 cannot implicitly convert type ‘string’ to ‘int’!
Obligatory link to wat? video
If you’re consciously and intentionally using JavaScript like that, I don’t want to be friends with you.
It’s not that hard to understand what it is doing and why the decision was made to make it do that. JavaScript has a particular purpose and it’s mission is not consistency.
It’s not like TypeScript doesn’t exist if you just get lightheaded at the idea of learning JavaScript’s quirks and mastering using it despite them.
Scanned the article: neither mission, nor purpose, nor type coercion unga-bunga explained. Or was I expected to see the greatness of the language and be humbled by its glory and might?
Well then, rage against the machine for the next 30 years and see if they kill it in favor of a nice, strict language that everybody loves. Maybe you could suggest one here for consideration.
So, all you’ve mustered is some lame-ass whataboutism? Have a good day
So you don’t have a suggestion. Got it.
Of course. Nothing beats JS, oh guru mighty guru
So all you’ve mustered is some lame-ass ad-hominem? Have a good day
No, it just so happens I have a minute to talk about our lord and saviour JS. What is His holy and sacred mission?
It’s because
+
is two different operators and overloads based on the type to the left, while-
is only a numeric operator and coerces left and right operands to numeric. But frankly if you’re still using+
for math or string concatenation in 2025, you’re doing it wrong.I know nothing about javascript, what is wrong with using + for math? perhaps naively, I’d say it looks suited for the job
The native arithmetic operators are prone to floating point rounding errors
It’s my favorite language too, but I also find this hilarious.
What no type safety does to an MF…