Study Guide: JavaScript->Shell

You can play around with JavaScript in one of multiple shells, in interactive batch mode. This means that you can enter JavaScript one line at a time and have it immediately executed; and if you enter a statement that returns a value without assigning the value anywhere, the value is displayed.

For a list of shells, see the list referenced from Enternal links.


Mozilla Firefox uses SpiderMonkey JavaScript engine, which is available as a standalone interactive shell for multiple platforms. You can download it from:

Unzip the file, and run "js" from the command line. A prompt appears:


You can enter statements, one at a time:

js> function incr(i) { return i+1; }
js> incr(1)
js> function plus2(i) {
return i+2;
js> plus2(1)
js> incr
function incr(i) { return i+1; }
js> print ("1+1:"+incr(1))
js> console.log("Yep.") // Console is available

Multi-line function definitions can be entered one line at a time, pressing enter after each line.

To run JavaScript snippets that use alert function--since they are intended for web browsers, you can define your own alert function:

js> function alert(message) { print ("Alert: "+message); }

From browser

You can have an interactive mode, entering JavaScript one line at a time and have it immediately executed, directly from your web browser.

In many versions of Firefox, press Control + Shift + K to get a web console window. At the bottom of the console window, there is a separate one-line field into which you can enter JavaScript lines and have them run by pressing Enter. Even multi-line function definitions can be entered, but not by pressing Enter but rather Shift + Enter and pressing Enter only after the whole definition was entered.

External links

  This article uses material from the Wikipedia page available here. It is released under the Creative Commons Attribution-Share-Alike License 3.0.



Connect with defaultLogic
What We've Done
Led Digital Marketing Efforts of Top 500 e-Retailers.
Worked with Top Brands at Leading Agencies.
Successfully Managed Over $50 million in Digital Ad Spend.
Developed Strategies and Processes that Enabled Brands to Grow During an Economic Downturn.
Taught Advanced Internet Marketing Strategies at the graduate level.

Manage research, learning and skills at Create an account using LinkedIn to manage and organize your omni-channel knowledge. is like a shopping cart for information -- helping you to save, discuss and share.

  Contact Us