76

JavaScript logic.

Comments
  • 3
    ParseInt to the rescue.
  • 1
    @Greggergalactic so when it comes to +, it adds the int to the char... I mean string.
    And when it comes to -, it doesn't concatenate... but why? Is there no way to do something like "reverse concatenation" (this is obviously a made up acronym BTW)
  • 6
    @demiko It doesn't, it will do the same if string is first. I suppose designers assumed that it is more common to concat string and other types without casting them, than it is to do numerical operations on non numerical types. From my own experience I find this to be true.

    They could have of course do some fancy checks to see if all values will evaluate to numerical types and choose to do numerical operation instead by I personally prefer that it is just "If one value is string and you are using string operator then it will be always string operator that is used".
  • 0
    @Greggergalactic No, that makes sense in normal speaking. THAT IS FUCKED UP IN PROGRAMMING.
  • 1
    Why not use & for concat and + for adding
  • 5
    @ctrlz someone needs to learn about bitwise operators.
  • 0
    You need to be a cat person to like javascript
  • 1
  • 1
    @Greggergalactic
    Idk it was a product of brainstorming. Maybe it doesn't exist... just a thought :)
  • 1
    @ctrlz or why not use ++ for concatenate
  • 0
    @nicholai he is making a pun to BASIC...
Add Comment