News for hackers. Stuff that matters.
Re:JSFuck (2012) by thamer on Saturday September 25, 2021 @10:50PM (#28658030)
In case anyone is wondering, the answer is '' (empty string).
Re:JSFuck (2012) by najmlion on Sunday September 26, 2021 @03:15AM (#28659032)
How can adding two empty arrays give you an empty string?
Re:JSFuck (2012) by superice on Sunday September 26, 2021 @03:44AM (#28659140)
The + operator doesn’t work on arrays, but tries to cast the sides of it to a string. Arrays implement the toString function, which shows the toString of the individual values comma separated. An empty array returns an empty string. Which means that this is equivalent to empty string + empty string.

[ ‘foo’, ‘bar ] + [ ‘baz’ ] would return ‘foo,barbaz’

Re:JSFuck (2012) by abdusco on Sunday September 26, 2021 @03:37AM (#28659120)
That's Javascript for you.

Summing arrays calls `.toString()` on them, and two empty string gives you a new empty string.

    [].toString() === ''
    [] + [] 
        === '' + '' 
        === ''
https://github.com/denysdovhan/wtfjs#adding-arrays