130

JS is love indeed

Comments
  • 21
    I 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.
  • 3
    @vishal-vp that's the saddest JS story I have heard 😂
  • 1
    @vishal-vp perhaps to understand JavaScript intricacies so you can avoid them in production code and not get bit in the ass?
  • 7
    I dont see inconsistencies? Every operator is doing exactly what it should.
  • 2
    But 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
  • 1
    @vishal-vp no wonder we have so many dropouts in cs
  • 0
    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 ?
  • 1
    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
  • 0
    Then typescript change the clusterfucj
  • 1
    Just use parseInt/parseFloat and stop whining. You’re doing math with strings and complaining that it’s weird.
  • 1
    All of these make perfect sense, except for Anon using an asterisk for an equals sign
Add Comment