Skip to content

Instantly share code, notes, and snippets.

@exbotanical
Created July 9, 2020 20:41
Show Gist options
  • Save exbotanical/6b6e6c0e6a397d79695521eaa2af4d7d to your computer and use it in GitHub Desktop.
Save exbotanical/6b6e6c0e6a397d79695521eaa2af4d7d to your computer and use it in GitHub Desktop.
Code Golf with JavaScript
/* Nodejs Quines */
// everything is wrapped in its own execution context so you can copy + paste the entire snippet without conflicts;
// else, the liberal use of semicolons (and in some instances, the lack thereof) will confuse the interpreter and throw exceptions
// IIFE ES6 quine
{
(x=_=>console.log(`(x=${x})();`))();
// 36 bytes
}
// ES6 Quine, shortest I've written thus far
{
$=_=>console.log(`$=${$};$()`);$()
// 34 bytes
}
// ES6 Quine writing to stdout
{
(y=_=>process.stdout.write(`(y=${y})()`))()
// 43 bytes
}
// Variation
{
(x=_=>console.log(`(x=${x.toString()})()`))()
// 46 Bytes
}
// If you have more performant/smaller JS Quines or otherwise suggestions for improvement regarging mine, please do share!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment