A command-line interface for JavaScript and DOM.

Open the shell or get the Shell bookmarklet (Firefox only).

Features

You can enter statements and expressions at the same prompt.

The result of each non-void statement or expression is shown.

User-defined variables. b = document.body

User-defined functions. function f() { return 5; }

JavaScript error messages are shown in red.

Previous statements and expressions are available through Up and Down arrow keys.

Tab completion.

Multiline input (Shift+Enter to insert a line break).

If the shell is opened using a bookmarklet, JavaScript typed into the shell runs in the context of the original window.

Works well in Firefox, mostly works in Opera 8 and in IE 6 for Windows.

Built-in functions

ans : the result of the previous expression.

: the result of the previous expression. print(expr) : prints expr on its own line. for(i = 0; i < 6; ++i) print( i * i )

: prints expr on its own line. pr(expr) : prints and returns its input, so you can use it to print intermediate results in the middle of an expression. function fact(n) { return n>0 ? pr( n*fact(n-1) ) : 1 }

: prints and returns its input, so you can use it to print intermediate results in the middle of an expression. blink(node) or Alt+B : makes a node blink for a second. blink( document.links[3] )

or : makes a node blink for a second. props(obj) or Alt+P : lists the methods and fields of an object. props( document.body ) In Firefox, props also shows which properties belong to the object itself and which belong to objects in its prototype chain.

or : lists the methods and fields of an object.

Suggested uses

Test short bits of JavaScript, bookmarklets, or user scripts. (For longer bits of JavaScript, try the JavaScript development environment too.)

Explore DOM objects such as document.body using props ( Alt+P ) to figure out what is possible.

using ( ) to figure out what is possible. Explore the DOM of a specific page using the bookmarklet version of the shell.

Modify the DOM of a specific page using the bookmarklet version of the shell.

Use the shell like you would use the home screen of a calculator such as a TI-83. Alt+M gives you easy access to math functions such as sin and pow .

About

The JavaScript shell was created by Jesse Ruderman. Ted Mielczarek added the tab completion feature in 1.1, Edward Lee added the multiline input feature in 1.2, and Jesper Rønn-Jensen fixed a few bugs for 1.4. Changelogs for some versions are available. The JavaScript Shell is GPL/LGPL/MPL tri-licensed.

Last modified October 30, 2005.