Comment


// Single line comment 

/* 
Multiple 
line 
comment
*/
          

Variable


// Declaration
var stuff;
// Assignment
stuff = "stuff";

// Declaration and assignment
var stuff = "stuff";
          

String


"Single line string";
          

Integer


42;
          

Boolean


true;
// or 
false;
          

Array


["stuff", "things"];
          

Dictionary


{"stuff_key": "stuff_value", "things_key": "things_value"};
          

For Loop


// Iterate list
for (var i=0; i < things.length; i++) {
    console.log(things[i]);
}

// Alternate syntax
for (var i in things) {
    console.log(things[i]);
}

// Iterate dictionary

          

While Loop


var i = 0;
while (i < things.length) {
    console.log(things[i]);
    i++;
}
          

If, Else if, Else


if (1 > 42) {
    console.log("One");
} else if (42 < 1) {
    console.log("The answer");
} else {
    console.log("Maths is fun");
}
          

Function


function stuff() {
    stuff = ["stuff", "things"];
    return stuff;
}