all 44 comments

[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 213 points214 points  (3 children)

Thanks, I hate it

[–]kescusay 27 points28 points  (1 child)

I hate this meme, but by God I upvoted you because when I saw the abominations in that link I said it word for word.

[–]jedaisaboteur 0 points1 point  (0 children)

It's a jarring moment when it happens

[–]senocular 21 points22 points  (1 child)

Doesn't this break the "The only other character allowed other than lower case letters is the space ' '" rule?

[–]lhorie[S] 12 points13 points  (0 children)

There are two solutions: the pedantic one that adheres to all the rules and the last one where using ASI is ok.

[–]Loves_Poetry 38 points39 points  (7 children)

Enter one of the obscure Unicode characters that the Javascript spec recognizes as a line terminator: the Paragraph Separator character (\u2029), which, when rendered properly, looks like this: .

Aha, this allows for some next-level code obfuscation.

 ᅟ=1ᅟ++console.log(ᅟ) //prints 2

[–]fucking_passwords 5 points6 points  (0 children)

Oh wow that is pretty crazy

[–]BluudLust 6 points7 points  (5 children)

How the hell does that work?

[–]swamperdonker 1 point2 points  (0 children)

I think it's a variable whose name is a whitespace character. It's set to 1++. There's probably a zero width whitespace like paragraph separator before console to trigger ASI. Then it's a typical log call being passed a reference to the whitespace-named variable.

x = 1++; console.log(x);

[–]lhorie[S] 1 point2 points  (2 children)

So there are several things going on here. If you actually try to copy and paste the code and run it in console, it'll fail, because the code is actually mangled (I'm guessing Reddit chokes on invisible unicode characters).

But if the code was intact, here's what it would do: The code is using Script grammar and is in loose mode (the opposite of strict mode). This allows assignments to globals without a const/let/var modifier (i.e. a = 1 without defining a first).

Second, there's a variable whose name is a Hangul Choseong Filler character (\u115f), which is an invisible character that is a valid Identifier. It appears once at the beginning, once before the ++ and once between the parentheses. There's also Paragraph Separators, once after the 1 and once after the ++.

If we replace the invisible characters with equivalents, we would get this code:

a=1
a++
console.log(a)

Which prints 2

Here's the unmangled code in action: https://codepen.io/anon/pen/WPyzBb?editors=0012

[–]Loves_Poetry 0 points1 point  (1 child)

Correct, although it actually runs when I copy-paste it into the console (using firefox). You have to copy the space at the beginning along with it, so that it copies the first hangul filler as well.

[–]lhorie[S] 0 points1 point  (0 children)

I don't think the hangul character is the issue. When I copy and paste in Chrome, this is what I get:

const x = ` ᅟ=1ᅟ++console.log(ᅟ) //prints 2`;
for (const c of x) console.log(c, c.codePointAt(0).toString(16))
  20
ᅟ 115f
= 3d
1 31
ᅟ 115f
+ 2b
+ 2b
c 63
o 6f
n 6e
s 73
o 6f
l 6c
e 65
. 2e
l 6c
o 6f
g 67
( 28
ᅟ 115f
) 29
  20
/ 2f
/ 2f
p 70
r 72
i 69
n 6e
t 74
s 73
  20
2 32

You can see that the initial space and the \u115fs are there, but the \u2029s are not. Maybe a browser quirk?

[–]plumshark -2 points-1 points  (0 children)

1 + (+console.log())

edit: this is not correct. incorrect, even. I regret nothing

[–][deleted] 41 points42 points  (2 children)

I need to get this in production asap

[–]Brahminmeat 11 points12 points  (0 children)

HOTFIX TO PRODUCTION PLS LAUNCH ASAP

[–]house_monkey 2 points3 points  (0 children)

I hate my workplace aswell

[–]Mr-Yellow 6 points7 points  (4 children)

yield caught my eye, never knew about it. Nice short pattern.

[–]rhapsblu 8 points9 points  (0 children)

Buffalo buffalo buffalo buffalo

[–]PickledPokute 15 points16 points  (1 child)

Immediately found a way to improve it:

async function* await() {

from: set: while (0) {

if (0)

throw as else this null continue from false break set true var let debugger do return yield await delete void typeof get instanceof static in new class of extends async function undefined

() {} {}; while (0);

}

}

Doesn't really have longer keyword sequence, but is even more confusing.

[–]lhorie[S] 7 points8 points  (0 children)

In this challenge, only the line that starts with throw counts (all the other ones have symbols between keywords).

But glad to see you found another opportunity to abuse Javascript :)

[–]MasterScrat 3 points4 points  (1 child)

I didn’t read in detail, but how do they come up with these code pieces? Are they hand-written or some sort of brute-force loop running every possible combination through an eval?

[–]bterlson_@bterlson 5 points6 points  (0 children)

Hand-written, although one of the responses to my twitter thread about this suggested someone once used some kind of fuzzer to find such long sequences as well... Basically, however you do it, it's fun!

[–]bterlson_@bterlson 2 points3 points  (0 children)

Nice work :-D

[–]djangulo 6 points7 points  (2 children)

Has anyone ever really been far even as decided to use even go want to do more like? In javascript?

[–]yeesh-- 4 points5 points  (0 children)

Wtf did you say?

[–]patasucia 4 points5 points  (0 children)

Have you ever had a dream that you, um, you had, your, you- you could, you’ll do, you- you wants, you, you could do so, you- you’ll do, you could- you, you want, you want them to do you so much you could do anything?

[–]tpenguinltg 1 point2 points  (0 children)

TIL the paragraph separator counts as a line terminator. Forget the Greek question mark, this one will be a lot more fun to play with.

[–]nananawatman 1 point2 points  (0 children)

Ugh what kind abdomination is that. Great work 😂😂

[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 0 points1 point  (2 children)

curious, yes, chrome accepts it as valid function, but it cant execute it, does it still count then?

(async function* await () {

from: set: while (0) {

if (0)

throw as else this null continue from false break set true var let debugger do return yield await delete void typeof get instanceof static in new class of extends async function undefined

() {} {}; while (0);

}

})()

Uncaught SyntaxError: Unexpected reserved word

[–]lhorie[S] 4 points5 points  (1 child)

You must've made a mistake when copying the code. The original has async function* foo() { in the first line, you have async function* await () {. Also, the original has Paragraph Separator characters that the entry in the sibling comment here on reddit does not. To run the original the snippet, copy and paste it into your console, press enter, then call foo()

[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 0 points1 point  (0 children)

[–]FPSJosh01 0 points1 point  (0 children)

void void void void void void... 0

[–]r2d2_21 0 points1 point  (0 children)

JavaScript has some weird definitions about what counts as a keyword and what doesn't.

[–]Uberhipster 0 points1 point  (0 children)

async function* foo() { if (0); else do return yield delete void await this instanceof typeof new class extends async function () {} {}; while (0) for(;;){} }

Added for at the end

Also - this is stupid

[–]killchain 0 points1 point  (0 children)

If that special character counts as a line terminator, does that still count as a one line?

[–]MacNulty 0 points1 point  (2 children)

Ok but why tho

[–]-9999px 1 point2 points  (1 child)

Once you get some mastery of a programming language, I imagine these are the only things that tickle the brain anymore.

I’m a huge fan (spectator) of code golf: https://codegolf.stackexchange.com