Simple JS Interpretter: Here's a small web page you can use to test JavaScript code.

posted 2000-Mar-29

One day someone on IRC (#javascript) asked how to convert '500px' to 500. I said that I thought parseInt() would work, but wasn't sure.

I frequently need a quick way to just run a bit of javascript code and see the result. I know you can do this in Netscape's javascript console, but I use IE as my main browser.

Following is a very simple HTML page which allows you to enter JavaScript code into a form and see the results. The last evaluated value gets alerted to you, so just entering:

parseInt('500px')

yields an alert of '500' (I was right! Yay!).

Change JS code below, and tab out of the field for your result:

However, you can also enter more complex code, even including functions. e.g.

function sq(x){
   return (x*x);
}

sq(25);
alerts you with '625'
var msg = "";
for (var i=0; i<10; i+=2){
  msg += (i+"\r");
}
msg;
gives a list of numbers from 0 to 8. And so on.

The simple page, which can be stored locally and bookmarked:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head><title>JavaScript Evaluator</title></head>
<body onLoad="document.forms[0].elements[0].select()">
<form onsubmit="return false" action="#" method="get">
Change JS code below, and tab out of the field for your result:<br>
<textarea onchange="alert(eval(this.value))" rows="10" cols="80">
var foo = "Hello";
foo +=" World";
</textarea>
</form>
</body>
<!-- written by Gavin Kistner : http://phrogz.net/nodes/jsinterpretter.asp -->
</html>
Enjoy!
Gavin Kistner
04:11PM ET
2003-Oct-30
See http://phrogz.net/tmp/simplejs.html for a better version.
net.mind details contact résumé other
Phrogz.net