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
-
v-vp34117yI remember I was in a web development course where I was asked MCQ based on these inconsistencies. I mean, what is the fucking point of asking questions based on these. -
Scipio6767y@vishal-vp perhaps to understand JavaScript intricacies so you can avoid them in production code and not get bit in the ass? -
Liz37127yBut i get the behavior at least for the - since the + is a multifunctional operator in most high level languages for string concatenation while the - is not and js is weakly typed -
Typescript fixes this by knowing what types your dealing with. Like what do you expect to happen when you add an int to a string ?
-
I feel it’s perfectly make sense.
String concat a number will return a string. Minus can only applies on numbers. What does ‘5’+-‘2’ even mean? String cannot subtract, so ‘5’+(-2) is squat to ‘5-2’.
‘5’+3-3=‘53’-3=50’
(5-3)+3=5 -
devios156307yJust use parseInt/parseFloat and stop whining. You’re doing math with strings and complaining that it’s weird. -
All of these make perfect sense, except for Anon using an asterisk for an equals sign
Related Rants

What only relying on JavaScript for HTML form input validation looks like
Found something true as 1 == 1
JS is love indeed
rant
js