120

Javascript why? (-‸ლ)

Comments
  • 8
    That is just wonderful.
  • 7
    Just when I thought I've understood JavaScript😫 .... baNaNa! .... This z just crazy!!!
  • 11
    JS really has the most fucked up coercion rules I've ever seen
  • 40
    ('b' + 'a' + + 'a' + 'a').toLowerCase()

    + 'a' is NaN
    ('b' + 'a' + NaN + 'a').toLowerCase()

    everything gets casted to string and concatenated

    ('baNaNa').toLowerCase()

    banana

    js's type handling is kind of nuts. Try the following

    []+{}*[]+[]+{}*[]+[]+{}*[]+[]+{}*[]+[]+{}*[]+[]+{}*[] + " batman!"
  • 13
    For those who would like explanation, taken from https://freecodecamp.org/news/...

    Unary + operator has higher precedence over binary + operator. So essentially what it does is:

    ('b'+'a'+ (+'a') + 'a').toLowerCase();

    Unary plus triggers numeric conversion for string 'a'. Since the string does not represent a valid number, the result is NaN. On the next step, expression 'ba' + NaN + 'a' is evaluated.
  • 1
    @dozingncoding 10/10 would destroy all software again
  • 1
    @dozingncoding Nananana batman !
  • 0
    Lol!!!
Add Comment