Online JavaScript Interpreter: Programming anywhere, nothing to install, works in any browser
Type your JavaScript program into the box below. Then click the Run button to see the result. To save your work, select the text and copy it to an editor or email it to yourself.
Type JavaScript     Examples: Use Library:     Output     Timing: s
Note that this is dynamic code running locally on your computer. The code will usually be retained in browser storage (localStorage) after you press Run.

Quick reference to basic JavaScript commands. W3Schools Javascript Tutorial

Comment
// this is a one-line comment
/* this comment could contain linebreaks */
Constant numbers 12.3 and strings "hi", "hi".charAt(0) is "h"
Variable start with a letter, then use letters, digits or _ (declared with var)
Expression built from +, -, *, /, pow(x,y), sqrt(), PI, E, log(), floor(), ceil(),
random(), sin(), cos(), tan(), atan() and constants, variables, functions
Assignment
v = expression;
Block
{   statement 1;
    ...
    statement n;
}
Condition expression == expression or <=, <,> , >=, !=...
or !cond, cond1 && cond2, cond1 || cond2
if - else
if (condition) block 1
else block 2                   // optional
for-loop
for (var i=start; endcondition; i++)
    block
while-loop
while (condition) 
    block
Function
f = function(v1, ..., vn) {
    statement 1;
    ...
    return expression;
}
List (array)
a = [1,2,"hi"]
a[0] is 1, a.length is 3, a.concat([4]) is [1,2,"hi",4]
Object
(hash tables)
object = {attribute:expression, method:function}
a = {x:2, y:3, s:function(){return this.x+this.y}}
a.x is 3, a["x"] is 3, a.s() is 5
Output
write("Hello"); writeln(" world");

This page is useful for experimenting with basic JavaScript and algorithms. It should work in any browser that has JavaScript enabled (including smartphones).

You can save your own local copy of this page (using Save As...), and use it even when you are not connected to the internet.


Portions Copyright Chapman University