Skip to content

Instantly share code, notes, and snippets.

@neerajkanhere
Forked from tlrobinson/LICENSE.txt
Created May 13, 2025 13:14
Show Gist options
  • Save neerajkanhere/813eaa59d97c75c970ab986df873a9e6 to your computer and use it in GitHub Desktop.
Save neerajkanhere/813eaa59d97c75c970ab986df873a9e6 to your computer and use it in GitHub Desktop.
Simple JavaScript REPL for the browser.

Simple JavaScript REPL for the browser.

By default it evals JS:

repl() // JavaScript eval mode

but you can pass it a callback instead:

repl(function(s) { return eval(s); });

The second argument is the default message first displayed:

repl(null, "eval some JS!");
function(c,t,h,r){
// history
h=[t||""];
// loop until blank input or cancel
// print last 10 reults
while(s=prompt(h.slice(-10).join("\n"))){
// eval the input, coerce to string, push onto history
// TODO: JSON.stringify() or other pretty printing?
try{
r=(c||eval)(s)
}catch(e){
r=e
}
h.push(""+r)
}
}
function(c,t,h,r){h=[t||""];while(s=prompt(h.slice(-10).join("\n"))){try{r=(c||eval)(s)}catch(e){r=e}h.push(""+r)}}
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Tom Robinson <http://tlrobinson.net/>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "simpleREPL",
"description": "Simple JavaScript REPL for the browser.",
"keywords": [
"repl",
"browser",
"javascript"
]
}
<!DOCTYPE html>
<title>Simple REPL</title>
<div>Enter some JavaScript. Cancel or empty input to exit.</div>
<script>
repl = function(c,h,r){h=[];while(s=prompt(h.slice(-10).join("\n"))){try{r=(c||eval)(s)}catch(e){r=e}h.push(""+r)}}
repl();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment