i guess follow me @bethposting on bsky or pillowfort


discord username:
bethposting

lexi
@lexi

so i tweeted this two days ago:

i just set my mind that i want to break the js quine golf WR. if you don't hear from me in the next 2 months you know what's up ✌️ like fucking hell there has to be a shorter solution

and the internet (code golf stackexchange, code.golf etc) have pretty much all agreed that the world record for a JS quine1 is 21+n (see footnote 2) characters. there are two optimal solutions:

f=p=>`f=${f};f()`;f()
(f=p=>`(f=${f})()`)()

if you are not as fluent in javascript code golf and want to know what that code does: someone made an in-depth explanation about one of them, and the other solution just uses braces instead of a semicolon and an explicit call. and that is the world record for node.js, node.js REPL, all major browser consoles, d8 etc.

but if you read the title you already know where this is going. i have found a 17+n character quine for node.js, or specifically the REPL:

p=>p+`
_(_)`
_(_)

this is pretty cool because a) i am pretty sure that that is a new WR (its 19% less code than before!!!! and this solution is nowhere on the internet) and b) it abuses the result of last line keyword3 in the REPL, which makes this pretty hard. _ just returns the result of the last thing you entered. the problem is this: if you use semicolons to separate your statements, _ will not select the last statement but the last line. so if you would run p=>p+';_(_)';_(_) it will fail because _ is not the function but the thing that was in your REPL before. so i have to strategically use a template string and newlines to make a new line without breaking the quine.

pretty neat if you ask me


  1. a quine is a program that prints its own source code. if you haven't tried writing one, try it! its a fun exercise in pretty much all programming languages

  2. 21+n, with n being the amount of characters for outputting the result (or in other words the boilerplate). for example, 1+2, write(1+2) and console.log(1+2) are 3+0, 3+7 and 3+13 characters respectively

  3. it technically isn't a keyword, but behaves like one


You must log in to comment.