3

Wtf, Javascript!!

Last week, I tweeted this

title text

When you run this on the console, it logs Friday!!!. Yes it does. It blew my mind and so did everyone's in the comments.

why, how, WTF!!

JS f***

It all started when I was listening to one of my favourite Javascript podcasts JS Party and on this episode, they were talking about weird Javascript syntax. One of the things they mentioned was this way of writing JS, it fascinated me and so I went on a deep dive into it.

That's how I found JSFuck, an esoteric and educational programming style besed on the atomic parts of Javascript.

console.log([]); // []
 
console.log(+[]); // 0
 
console.log(![]); // false
 
console.log(![] + []); // 'false'

The main idea is that there exists a very specific set of symbols and characters that can be used to write the code. In the example above, we see how we can use the [] character to get a number and a string by using the +(plus sign) to cast the array literal to a string. The plus sign can also be used to: - Add two values (of course) - Create numbers (!![]+!![] will give us 2) - Create strings - Concatenate strings

The other main character in the JSFuck set is the ! (Logical NOT operator). This one is mainly used to cast to boolean and from there, we can convert the booleans to strings and further access the individual string characters.

console.log(!![]); // true
 
console.log(!![] + []); // 'true'

The double NOT operators cast the empty array to a boolean value, adding an empty array to the boolean value gives us a string character. So if we wanted the letter t, we'd get it by (!![]+[])[![]+![]].

console.log((!![] + [])[![] + ![]]); // 't'

Breaking this down, there are 2 parts to this: - Generating the string - Accessing the single element

(!![]+[]) gives us 'true', next, we just need to access the string character, normally, we'd do this by using [0], but this is JSFuck, we have to abstract the 0, so it becomes [![]+![]], which is essentially false+false.

Anyway, this is not something you'd write maybe never, but it is cool to know it exists. It has been fun watching my friends loose their minds when I show them this.

Other languge esometrics are being built from the motivation of JSFuck, there's PyFuck btw. If I can learn Go fast enough, I can build GoFuck, which is a really good name btw.

That's all...

console.log(
  [][
    (![] + [])[+[]] +
      (![] + [])[!+[] + !+[]] +
      (![] + [])[+!+[]] +
      (!![] + [])[+[]]
  ][
    ([][
      (![] + [])[+[]] +
        (![] + [])[!+[] + !+[]] +
        (![] + [])[+!+[]] +
        (!![] + [])[+[]]
    ] + [])[!+[] + !+[] + !+[]] +
      (!![] +
        [][
          (![] + [])[+[]] +
            (![] + [])[!+[] + !+[]] +
            (![] + [])[+!+[]] +
            (!![] + [])[+[]]
        ])[+!+[] + [+[]]] +
      ([][[]] + [])[+!+[]] +
      (![] + [])[!+[] + !+[] + !+[]] +
      (!![] + [])[+[]] +
      (!![] + [])[+!+[]] +
      ([][[]] + [])[+[]] +
      ([][
        (![] + [])[+[]] +
          (![] + [])[!+[] + !+[]] +
          (![] + [])[+!+[]] +
          (!![] + [])[+[]]
      ] + [])[!+[] + !+[] + !+[]] +
      (!![] + [])[+[]] +
      (!![] +
        [][
          (![] + [])[+[]] +
            (![] + [])[!+[] + !+[]] +
            (![] + [])[+!+[]] +
            (!![] + [])[+[]]
        ])[+!+[] + [+[]]] +
      (!![] + [])[+!+[]]
  ](
    (!![] + [])[+!+[]] +
      (!![] + [])[!+[] + !+[] + !+[]] +
      (!![] + [])[+[]] +
      ([][[]] + [])[+[]] +
      (!![] + [])[+!+[]] +
      ([][[]] + [])[+!+[]] +
      (+[![]] +
        [][
          (![] + [])[+[]] +
            (![] + [])[!+[] + !+[]] +
            (![] + [])[+!+[]] +
            (!![] + [])[+[]]
        ])[+!+[] + [+!+[]]] +
      (!![] + [])[!+[] + !+[] + !+[]] +
      (+(!+[] + !+[] + !+[] + [+!+[]]))[
        (!![] + [])[+[]] +
          (!![] +
            [][
              (![] + [])[+[]] +
                (![] + [])[!+[] + !+[]] +
                (![] + [])[+!+[]] +
                (!![] + [])[+[]]
            ])[+!+[] + [+[]]] +
          ([] + [])[
            ([][
              (![] + [])[+[]] +
                (![] + [])[!+[] + !+[]] +
                (![] + [])[+!+[]] +
                (!![] + [])[+[]]
            ] + [])[!+[] + !+[] + !+[]] +
              (!![] +
                [][
                  (![] + [])[+[]] +
                    (![] + [])[!+[] + !+[]] +
                    (![] + [])[+!+[]] +
                    (!![] + [])[+[]]
                ])[+!+[] + [+[]]] +
              ([][[]] + [])[+!+[]] +
              (![] + [])[!+[] + !+[] + !+[]] +
              (!![] + [])[+[]] +
              (!![] + [])[+!+[]] +
              ([][[]] + [])[+[]] +
              ([][
                (![] + [])[+[]] +
                  (![] + [])[!+[] + !+[]] +
                  (![] + [])[+!+[]] +
                  (!![] + [])[+[]]
              ] + [])[!+[] + !+[] + !+[]] +
              (!![] + [])[+[]] +
              (!![] +
                [][
                  (![] + [])[+[]] +
                    (![] + [])[!+[] + !+[]] +
                    (![] + [])[+!+[]] +
                    (!![] + [])[+[]]
                ])[+!+[] + [+[]]] +
              (!![] + [])[+!+[]]
          ][
            ([][[]] + [])[+!+[]] +
              (![] + [])[+!+[]] +
              ((+[])[
                ([][
                  (![] + [])[+[]] +
                    (![] + [])[!+[] + !+[]] +
                    (![] + [])[+!+[]] +
                    (!![] + [])[+[]]
                ] + [])[!+[] + !+[] + !+[]] +
                  (!![] +
                    [][
                      (![] + [])[+[]] +
                        (![] + [])[!+[] + !+[]] +
                        (![] + [])[+!+[]] +
                        (!![] + [])[+[]]
                    ])[+!+[] + [+[]]] +
                  ([][[]] + [])[+!+[]] +
                  (![] + [])[!+[] + !+[] + !+[]] +
                  (!![] + [])[+[]] +
                  (!![] + [])[+!+[]] +
                  ([][[]] + [])[+[]] +
                  ([][
                    (![] + [])[+[]] +
                      (![] + [])[!+[] + !+[]] +
                      (![] + [])[+!+[]] +
                      (!![] + [])[+[]]
                  ] + [])[!+[] + !+[] + !+[]] +
                  (!![] + [])[+[]] +
                  (!![] +
                    [][
                      (![] + [])[+[]] +
                        (![] + [])[!+[] + !+[]] +
                        (![] + [])[+!+[]] +
                        (!![] + [])[+[]]
                    ])[+!+[] + [+[]]] +
                  (!![] + [])[+!+[]]
              ] + [])[+!+[] + [+!+[]]] +
              (!![] + [])[!+[] + !+[] + !+[]]
          ]
      ](!+[] + !+[] + !+[] + [!+[] + !+[]]) +
      (![] + [])[+!+[]] +
      (![] + [])[!+[] + !+[]]
  )()(
    [][
      (![] + [])[+[]] +
        (![] + [])[!+[] + !+[]] +
        (![] + [])[+!+[]] +
        (!![] + [])[+[]]
    ][
      ([][
        (![] + [])[+[]] +
          (![] + [])[!+[] + !+[]] +
          (![] + [])[+!+[]] +
          (!![] + [])[+[]]
      ] + [])[!+[] + !+[] + !+[]] +
        (!![] +
          [][
            (![] + [])[+[]] +
              (![] + [])[!+[] + !+[]] +
              (![] + [])[+!+[]] +
              (!![] + [])[+[]]
          ])[+!+[] + [+[]]] +
        ([][[]] + [])[+!+[]] +
        (![] + [])[!+[] + !+[] + !+[]] +
        (!![] + [])[+[]] +
        (!![] + [])[+!+[]] +
        ([][[]] + [])[+[]] +
        ([][
          (![] + [])[+[]] +
            (![] + [])[!+[] + !+[]] +
            (![] + [])[+!+[]] +
            (!![] + [])[+[]]
        ] + [])[!+[] + !+[] + !+[]] +
        (!![] + [])[+[]] +
        (!![] +
          [][
            (![] + [])[+[]] +
              (![] + [])[!+[] + !+[]] +
              (![] + [])[+!+[]] +
              (!![] + [])[+[]]
          ])[+!+[] + [+[]]] +
        (!![] + [])[+!+[]]
    ](
      (!![] + [])[+!+[]] +
        (!![] + [])[!+[] + !+[] + !+[]] +
        (!![] + [])[+[]] +
        ([][[]] + [])[+[]] +
        (!![] + [])[+!+[]] +
        ([][[]] + [])[+!+[]] +
        (+[![]] +
          [][
            (![] + [])[+[]] +
              (![] + [])[!+[] + !+[]] +
              (![] + [])[+!+[]] +
              (!![] + [])[+[]]
          ])[+!+[] + [+!+[]]] +
        (!![] + [])[!+[] + !+[] + !+[]] +
        (![] + [])[!+[] + !+[] + !+[]] +
        ([][
          (![] + [])[+[]] +
            (![] + [])[!+[] + !+[]] +
            (![] + [])[+!+[]] +
            (!![] + [])[+[]]
        ] + [])[!+[] + !+[] + !+[]] +
        (![] + [])[+!+[]] +
        (+(!+[] + !+[] + [+!+[]] + [+!+[]]))[
          (!![] + [])[+[]] +
            (!![] +
              [][
                (![] + [])[+[]] +
                  (![] + [])[!+[] + !+[]] +
                  (![] + [])[+!+[]] +
                  (!![] + [])[+[]]
              ])[+!+[] + [+[]]] +
            ([] + [])[
              ([][
                (![] + [])[+[]] +
                  (![] + [])[!+[] + !+[]] +
                  (![] + [])[+!+[]] +
                  (!![] + [])[+[]]
              ] + [])[!+[] + !+[] + !+[]] +
                (!![] +
                  [][
                    (![] + [])[+[]] +
                      (![] + [])[!+[] + !+[]] +
                      (![] + [])[+!+[]] +
                      (!![] + [])[+[]]
                  ])[+!+[] + [+[]]] +
                ([][[]] + [])[+!+[]] +
                (![] + [])[!+[] + !+[] + !+[]] +
                (!![] + [])[+[]] +
                (!![] + [])[+!+[]] +
                ([][[]] + [])[+[]] +
                ([][
                  (![] + [])[+[]] +
                    (![] + [])[!+[] + !+[]] +
                    (![] + [])[+!+[]] +
                    (!![] + [])[+[]]
                ] + [])[!+[] + !+[] + !+[]] +
                (!![] + [])[+[]] +
                (!![] +
                  [][
                    (![] + [])[+[]] +
                      (![] + [])[!+[] + !+[]] +
                      (![] + [])[+!+[]] +
                      (!![] + [])[+[]]
                  ])[+!+[] + [+[]]] +
                (!![] + [])[+!+[]]
            ][
              ([][[]] + [])[+!+[]] +
                (![] + [])[+!+[]] +
                ((+[])[
                  ([][
                    (![] + [])[+[]] +
                      (![] + [])[!+[] + !+[]] +
                      (![] + [])[+!+[]] +
                      (!![] + [])[+[]]
                  ] + [])[!+[] + !+[] + !+[]] +
                    (!![] +
                      [][
                        (![] + [])[+[]] +
                          (![] + [])[!+[] + !+[]] +
                          (![] + [])[+!+[]] +
                          (!![] + [])[+[]]
                      ])[+!+[] + [+[]]] +
                    ([][[]] + [])[+!+[]] +
                    (![] + [])[!+[] + !+[] + !+[]] +
                    (!![] + [])[+[]] +
                    (!![] + [])[+!+[]] +
                    ([][[]] + [])[+[]] +
                    ([][
                      (![] + [])[+[]] +
                        (![] + [])[!+[] + !+[]] +
                        (![] + [])[+!+[]] +
                        (!![] + [])[+[]]
                    ] + [])[!+[] + !+[] + !+[]] +
                    (!![] + [])[+[]] +
                    (!![] +
                      [][
                        (![] + [])[+[]] +
                          (![] + [])[!+[] + !+[]] +
                          (![] + [])[+!+[]] +
                          (!![] + [])[+[]]
                      ])[+!+[] + [+[]]] +
                    (!![] + [])[+!+[]]
                ] + [])[+!+[] + [+!+[]]] +
                (!![] + [])[!+[] + !+[] + !+[]]
            ]
        ](!+[] + !+[] + !+[] + [+!+[]])[+!+[]] +
        (!![] + [])[!+[] + !+[] + !+[]]
    )()(
      ([] + [])[
        ([![]] + [][[]])[+!+[] + [+[]]] +
          (!![] + [])[+[]] +
          (![] + [])[+!+[]] +
          (![] + [])[!+[] + !+[]] +
          ([![]] + [][[]])[+!+[] + [+[]]] +
          ([][
            (![] + [])[+[]] +
              (![] + [])[!+[] + !+[]] +
              (![] + [])[+!+[]] +
              (!![] + [])[+[]]
          ] + [])[!+[] + !+[] + !+[]] +
          (![] + [])[!+[] + !+[] + !+[]]
      ]()
    )[!+[] + !+[]] +
      (+(+!+[] + [+[]] + [+!+[]]))[
        (!![] + [])[+[]] +
          (!![] +
            [][
              (![] + [])[+[]] +
                (![] + [])[!+[] + !+[]] +
                (![] + [])[+!+[]] +
                (!![] + [])[+[]]
            ])[+!+[] + [+[]]] +
          ([] + [])[
            ([][
              (![] + [])[+[]] +
                (![] + [])[!+[] + !+[]] +
                (![] + [])[+!+[]] +
                (!![] + [])[+[]]
            ] + [])[!+[] + !+[] + !+[]] +
              (!![] +
                [][
                  (![] + [])[+[]] +
                    (![] + [])[!+[] + !+[]] +
                    (![] + [])[+!+[]] +
                    (!![] + [])[+[]]
                ])[+!+[] + [+[]]] +
              ([][[]] + [])[+!+[]] +
              (![] + [])[!+[] + !+[] + !+[]] +
              (!![] + [])[+[]] +
              (!![] + [])[+!+[]] +
              ([][[]] + [])[+[]] +
              ([][
                (![] + [])[+[]] +
                  (![] + [])[!+[] + !+[]] +
                  (![] + [])[+!+[]] +
                  (!![] + [])[+[]]
              ] + [])[!+[] + !+[] + !+[]] +
              (!![] + [])[+[]] +
              (!![] +
                [][
                  (![] + [])[+[]] +
                    (![] + [])[!+[] + !+[]] +
                    (![] + [])[+!+[]] +
                    (!![] + [])[+[]]
                ])[+!+[] + [+[]]] +
              (!![] + [])[+!+[]]
          ][
            ([][[]] + [])[+!+[]] +
              (![] + [])[+!+[]] +
              ((+[])[
                ([][
                  (![] + [])[+[]] +
                    (![] + [])[!+[] + !+[]] +
                    (![] + [])[+!+[]] +
                    (!![] + [])[+[]]
                ] + [])[!+[] + !+[] + !+[]] +
                  (!![] +
                    [][
                      (![] + [])[+[]] +
                        (![] + [])[!+[] + !+[]] +
                        (![] + [])[+!+[]] +
                        (!![] + [])[+[]]
                    ])[+!+[] + [+[]]] +
                  ([][[]] + [])[+!+[]] +
                  (![] + [])[!+[] + !+[] + !+[]] +
                  (!![] + [])[+[]] +
                  (!![] + [])[+!+[]] +
                  ([][[]] + [])[+[]] +
                  ([][
                    (![] + [])[+[]] +
                      (![] + [])[!+[] + !+[]] +
                      (![] + [])[+!+[]] +
                      (!![] + [])[+[]]
                  ] + [])[!+[] + !+[] + !+[]] +
                  (!![] + [])[+[]] +
                  (!![] +
                    [][
                      (![] + [])[+[]] +
                        (![] + [])[!+[] + !+[]] +
                        (![] + [])[+!+[]] +
                        (!![] + [])[+[]]
                    ])[+!+[] + [+[]]] +
                  (!![] + [])[+!+[]]
              ] + [])[+!+[] + [+!+[]]] +
              (!![] + [])[!+[] + !+[] + !+[]]
          ]
      ](!+[] + !+[] + [+!+[]])[+!+[]] +
      (!![] + [])[!+[] + !+[] + !+[]] +
      (!![] + [])[!+[] + !+[] + !+[]] +
      (!![] + [])[+!+[]] +
      (![] + [])[!+[] + !+[] + !+[]]
  )
);

All this to print Cheers, Daaamn!! I love this language :)