Explanation: it’s mostly due to how js does type conversion. for the Ls, it’s

[] is an empty array ![] is treated as false combining a boolean with the empty array returns “false” as a string (so true + [] = “true”, false + [] = “false”) ! + [] is treated as true ! + [] + ! + [] is treated as 2 since true + true = 1 + 1 = 2 so you have “false”[2], which is l for the o it’s [] is an empty array [] + {} returns “[object Object]” as a string ({} + [] returns 0) ![] is false !![] is true +!![] casts it to an integer so that part is “[object Object]”[1], which returns “o”

    • Deebster@lemmyrs.org
      link
      fedilink
      English
      arrow-up
      40
      arrow-down
      1
      ·
      edit-2
      1 year ago

      The line breaks haven’t worked, here’s it formatted correctly:

      Explanation: it’s mostly due to how js does type conversion.

      For the Ls, it’s:

      • [] is an empty array
      • ![] is treated as false
      • combining a boolean with the empty array returns “false” as a string (so true + [] = “true”, false + [] = “false”)
      • ! + [] is treated as true
      • ! + [] + ! + [] is treated as 2 since true + true = 1 + 1 = 2
      • so you have “false”[2], which is l

      for the o it’s:

      • [] is an empty array
      • [] + {} returns “[object Object]” as a string ({} + [] returns 0)
      • ![] is false
      • !![] is true
      • +!![] casts it to an integer
      • so that part is “[object Object]”[1], which returns “o”-
    • arandomthought@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      13
      ·
      edit-2
      1 year ago

      The idea behind it is not that complicated to explain… They set up a construct that spits out the word “false” and one that spits out “[object Object]”. Taking the character with the Index of 2 from “false” gives us the “l” (the “2” to use as the index is of course also created using only brackets and parentheses). The character with the index of 1 from “[object Object]” is “o”. So we have everything we need to spell out “lol”.