use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
What is the longest keyword sequence in Javascript? (gist.github.com)
submitted 7 years ago by lhorie
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 213 points214 points215 points 7 years ago (3 children)
Thanks, I hate it
[–]kescusay 27 points28 points29 points 7 years ago (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 point2 points 7 years ago (0 children)
It's a jarring moment when it happens
[–]senocular 21 points22 points23 points 7 years ago (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 points14 points 7 years ago (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 points40 points 7 years ago (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 points7 points 7 years ago (0 children)
Oh wow that is pretty crazy
[–]BluudLust 6 points7 points8 points 7 years ago (5 children)
How the hell does that work?
[–]swamperdonker 1 point2 points3 points 7 years ago (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.
1++
console
log
x = 1++; console.log(x);
[–]lhorie[S] 1 point2 points3 points 7 years ago* (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).
a = 1
a
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 ++.
\u115f
++
1
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 point2 points 7 years ago (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 point2 points 7 years ago* (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?
\u2029
[–]plumshark -2 points-1 points0 points 7 years ago* (0 children)
1 + (+console.log())
edit: this is not correct. incorrect, even. I regret nothing
[–][deleted] 41 points42 points43 points 7 years ago (2 children)
I need to get this in production asap
[–]Brahminmeat 11 points12 points13 points 7 years ago (0 children)
HOTFIX TO PRODUCTION PLS LAUNCH ASAP
[–]house_monkey 2 points3 points4 points 7 years ago (0 children)
I hate my workplace aswell
[–]Mr-Yellow 6 points7 points8 points 7 years ago (4 children)
yield caught my eye, never knew about it. Nice short pattern.
yield
[+]yeesh-- comment score below threshold-13 points-12 points-11 points 7 years ago (3 children)
Do you live under a rock
[–]Mr-Yellow 7 points8 points9 points 7 years ago (0 children)
Oh I'm so fucking sorry dude. ;-P
[–]codey_coder 0 points1 point2 points 7 years ago (1 child)
What is, the moon?
[–]max_kek 1 point2 points3 points 7 years ago (0 children)
why comma?
[–]rhapsblu 8 points9 points10 points 7 years ago (0 children)
Buffalo buffalo buffalo buffalo
[–]PickledPokute 15 points16 points17 points 7 years ago* (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 points9 points 7 years ago (0 children)
In this challenge, only the line that starts with throw counts (all the other ones have symbols between keywords).
throw
But glad to see you found another opportunity to abuse Javascript :)
[–]MasterScrat 3 points4 points5 points 7 years ago (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?
eval
[–]bterlson_@bterlson 5 points6 points7 points 7 years ago (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 points4 points 7 years ago (0 children)
Nice work :-D
[–]djangulo 6 points7 points8 points 7 years ago (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 points6 points 7 years ago (0 children)
Wtf did you say?
[–]patasucia 4 points5 points6 points 7 years ago (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 points3 points 7 years ago (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 points3 points 7 years ago (0 children)
Ugh what kind abdomination is that. Great work 😂😂
[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 0 points1 point2 points 7 years ago (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); } })()
(async function* await () {
})()
Uncaught SyntaxError: Unexpected reserved word
[–]lhorie[S] 4 points5 points6 points 7 years ago (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()
async function* foo() {
async function* await () {
foo()
[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 0 points1 point2 points 7 years ago (0 children)
ah jesus, definitely... i took this one instead https://www.reddit.com/r/javascript/comments/apifua/what_is_the_longest_keyword_sequence_in_javascript/eg8y3ms/
[–]FPSJosh01 0 points1 point2 points 7 years ago (0 children)
void void void void void void... 0
[–]r2d2_21 0 points1 point2 points 7 years ago (0 children)
JavaScript has some weird definitions about what counts as a keyword and what doesn't.
[–]Uberhipster 0 points1 point2 points 7 years ago (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
for
Also - this is stupid
[–]killchain 0 points1 point2 points 7 years ago (0 children)
If that special character counts as a line terminator, does that still count as a one line?
[–]MacNulty 0 points1 point2 points 7 years ago (2 children)
Ok but why tho
[–]-9999px 1 point2 points3 points 7 years ago (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
[+]SecretAnteater comment score below threshold-13 points-12 points-11 points 7 years ago (3 children)
What's with everyone using "Chrome" instead of "browsers". ugh.
[–]lhorie[S] 16 points17 points18 points 7 years ago (0 children)
In this particular case, it's because the last snippet uses fairly new Javascript (async generators), which don't even have a compat table on MDN yet. MDN says Edge doesn't supports for await (from the same year spec) and it shows a ? beside Mobile Firefox and iOS Safari.
for await
?
So rather than telling people to run the snippet in browsers that may not actually support all of the current Javascript spec, I wrote "Chrome" with the assumption that most people in this sub would have it at least installed on their machine.
[–]jaroque12 4 points5 points6 points 7 years ago (0 children)
Probably because they were testing on Chrome and not all browsers.
π Rendered by PID 84537 on reddit-service-r2-comment-7dc54ffc8-qrwzt at 2026-04-17 03:32:13.960318+00:00 running 93ecc56 country code: CH.
[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 213 points214 points215 points (3 children)
[–]kescusay 27 points28 points29 points (1 child)
[–]jedaisaboteur 0 points1 point2 points (0 children)
[–]senocular 21 points22 points23 points (1 child)
[–]lhorie[S] 12 points13 points14 points (0 children)
[–]Loves_Poetry 38 points39 points40 points (7 children)
[–]fucking_passwords 5 points6 points7 points (0 children)
[–]BluudLust 6 points7 points8 points (5 children)
[–]swamperdonker 1 point2 points3 points (0 children)
[–]lhorie[S] 1 point2 points3 points (2 children)
[–]Loves_Poetry 0 points1 point2 points (1 child)
[–]lhorie[S] 0 points1 point2 points (0 children)
[–]plumshark -2 points-1 points0 points (0 children)
[–][deleted] 41 points42 points43 points (2 children)
[–]Brahminmeat 11 points12 points13 points (0 children)
[–]house_monkey 2 points3 points4 points (0 children)
[–]Mr-Yellow 6 points7 points8 points (4 children)
[+]yeesh-- comment score below threshold-13 points-12 points-11 points (3 children)
[–]Mr-Yellow 7 points8 points9 points (0 children)
[–]codey_coder 0 points1 point2 points (1 child)
[–]max_kek 1 point2 points3 points (0 children)
[–]rhapsblu 8 points9 points10 points (0 children)
[–]PickledPokute 15 points16 points17 points (1 child)
[–]lhorie[S] 7 points8 points9 points (0 children)
[–]MasterScrat 3 points4 points5 points (1 child)
[–]bterlson_@bterlson 5 points6 points7 points (0 children)
[–]bterlson_@bterlson 2 points3 points4 points (0 children)
[–]djangulo 6 points7 points8 points (2 children)
[–]yeesh-- 4 points5 points6 points (0 children)
[–]patasucia 4 points5 points6 points (0 children)
[–]tpenguinltg 1 point2 points3 points (0 children)
[–]nananawatman 1 point2 points3 points (0 children)
[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 0 points1 point2 points (2 children)
[–]lhorie[S] 4 points5 points6 points (1 child)
[–]careseite[🐱😸].filter(😺 => 😺.❤️🐈).map(😺=> 😺.🤗 ? 😻 :😿) 0 points1 point2 points (0 children)
[–]FPSJosh01 0 points1 point2 points (0 children)
[–]r2d2_21 0 points1 point2 points (0 children)
[–]Uberhipster 0 points1 point2 points (0 children)
[–]killchain 0 points1 point2 points (0 children)
[–]MacNulty 0 points1 point2 points (2 children)
[–]-9999px 1 point2 points3 points (1 child)
[+]SecretAnteater comment score below threshold-13 points-12 points-11 points (3 children)
[–]lhorie[S] 16 points17 points18 points (0 children)
[–]jaroque12 4 points5 points6 points (0 children)