5
jowahe
3y

javascript be like :
"b" + "a" + +"a" + "a"; // -> 'baNaNa'

Comments
  • 1
    Yeah, just like any language when you use concatenation with strings ?
  • 1
    @Lyniven javascript turns + + "a" into NaN (Not a Number) its not string concatenation, it is implicit type conversion (something most languages don't do)
  • 1
    @ItsNotMyFault but that's also something you won't ever write on your right mind. Just as the legendary memes of saying "gnagnagna but what about !![]?
  • 0
    Automatic type conversion in general is just like any other booby trap:
    It waits for unsuspecting or unfocused coders to screw up their code in a hard to detect way - always going for the juicy runtime data corruption...

    If you design a language, just make the devs write explicit casts when they really want them. Makes everyone's life so much easier and gives the interpreter/compiler a chance to actually detect that sort of bug before corruption happens.
  • 0
    Funny joke but not a rant. I don't like JS but bashing it for trowing weak type shit at any dynamic typed language and than complain about the assumptions it made is just stupid. Same issues with PHP, Python, Perl, Bash.
  • 0
    @hjk101 not php it doesn't concat strings by overloading the + operator.

    But your point still stands!
  • 0
    @C0D4 My point was not about the + operator (Perl also uses the dot for concatenation). But in all these languages you have the same type of shenanigans with weak comparison and implicit coercion. For php there is a famous case of password hash comparison for example: https://darkreading.com/vulnerabili...
  • 0
    @hjk101 type conversion in python is always explicit. 'Hello' + 5 throws: TypeError: can only concatenate str (not "int") to str
  • 0
    @ItsNotMyFault yeah sorry python should not be in that list as it is strongly (but dynamically typed)
Add Comment