Skip to content

Instantly share code, notes, and snippets.

@chrismilson
Last active August 25, 2020 07:05
Show Gist options
  • Save chrismilson/24d0490b17cede42c1f68e3f6a8be865 to your computer and use it in GitHub Desktop.
Save chrismilson/24d0490b17cede42c1f68e3f6a8be865 to your computer and use it in GitHub Desktop.
Javascript Quine

The following javascript code will evaluate to itself:

(function f () {return `(${f})()`})()

That is, if x = (function f () {return `(${f})()`;})(), then x === eval(x) is true.

Code snippets like this are known as quines. I first learnt about quines in a video by the AI researcher and youtuber Lex Fridman.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment