Nerdworks logo "The nerd shall inherit the earth."

Nerdworks Blogorama

Nerdspeak

JavaScript eval console
Technobabble
3/31/2011 8:22:31 AM  

One of the things I frequently find myself needing to do as I explore the JavaScript language is to quickly code up little snippets of JavaScript code and run them. Once I'd tired myself of spinning up little HTML files scattered all over the place, I figured I'd write an interactive console of sorts where I can quickly experiment with JS code. Starting with a simple textarea embedded in an HTML page I eventually ended up with the page in its current incarnation. Here's a screen shot of the console in action:

The console uses Ajax.org and Mozilla's Ace web editor to get support for things like auto-indent and syntax highlighting. You can hit the keyboard combination Ctrl+Enter to make the console run the code that is currently in the console. The page automatically loads the latest version of jQuery for you so you have all the $ goodness available to you. There are also a bunch of built-in utility functions available that you can call. Here's a list:

Function What it does Example
print(msg) Prints the string passed to it to the output console. print("Hello.");
pprint(msg) Prints the string passed to it to the output console using <pre> tag. pprint("Pre-formatted hello.");
sprintf(fmt, ...) Similar to the 'C' sprintf function. Returns formatted string. Credit for function goes to http://www.webtoolkit.info/javascript-sprintf.html print(sprintf("ms since 1/1/1970: %d",
   Date.now()));
escapeHTML Use this function if you're trying to print a bit of HTML snippet to the console. If you directly print HTML then the console will simply render it! print(escapeHTML("<div>markup</div>"));
clear Clears the message log pane. clear();

If you'd like to access an online version of the console that you can run right away, then use this:

Run JavaScript Eval

If you'd prefer to use an offline version instead then download it here (note that Google Chrome seems to have problems running this page if served from the disk - so if you're running offline then please stick to IE9, FF or Safari):

Download JavaScript Eval
Link Comment (10)
 
blogorama home
about this blog
email the author
where on earth am i?
subscribe to mailing list
feeds Use these links for feed syndication
rss  |  atom
by category
technobabble (60)
philosophical crud (3)
irrelevant stuff (7)
archive
november, 2011 (2)
october, 2011 (1)
september, 2011 (7)
july, 2011 (3)
june, 2011 (2)
may, 2011 (3)
april, 2011 (1)
march, 2011 (1)
february, 2011 (1)
february, 2010 (1)
october, 2009 (1)
september, 2009 (1)
july, 2009 (5)
march, 2009 (2)
august, 2008 (2)
march, 2008 (1)
january, 2008 (1)
september, 2007 (2)
april, 2007 (1)
february, 2007 (2)
december, 2006 (1)
october, 2006 (1)
september, 2006 (4)
august, 2006 (3)
july, 2006 (4)
june, 2006 (3)
may, 2006 (6)
april, 2006 (2)
recent entries
Implementing variab...
Debugging existing...
Screen scraping wit...
Building an Instagr...
Building an Instagr...
Organizing your Jav...
297906 hits