Create a reference

var someVariable = true;

Create a function

var someFunction = function(a, b, c){
  console.log(a, b, c);
};
// or...
function someFunction(a,b,c){
  console.log(a, b, c);
}

Create an array

var someArray = [1,2,3];

Create an object

var someObject = {};

Assign properties to an object

someObject.someProperty = "someValue";
// or...
var someProperty = 'someProperty';
someObject[someProperty] = "someValue";
// or...
var someObject = {
  someProperty : "someValue",
  "anotherProperty" : 10
}

Iterate through an array

for(var i = 0, l = someArray.length; i < l; i++){
  console.log(someArray[i], i);
}
// or...
var i = someArray.length - 1;
for(; i >= 0; i--){
  console.log(someArray[i], i);
}
// or...
someArray.forEach(function(element, index){
  console.log(element, index);
});

Iterate over an object

for(var property in object){
  console.log(property, object[property]);
}
// or...
someObject.forEach(function(key, value){
  console.log(key, value);
});

Get a reference to an element

document.getElementById('some-id');
document.querySelector('#some-id');
document.querySelector('.more-sophisticated > .selector');
anotherElementReference.querySelector('#some-id');
anotherElement.firstChild;  // careful, might return a comment or text, not an element
anotherElement.firstElementChild;  // will not return comments or text, only elements
anotherElement.parentNode;
anotherElement.nextSibling;

Get a reference to a collection of elements

document.querySelectorAll('a');
anotherElementReference.querySelectorAll('.some-class > a');
anotherElementReference.getElementsByTagName('div');
anotherElementReference.getElementsByClassName('some-class');
anotherElementReference.childNodes;  // includes text and comments
anotherElementReference.children;  // only html elements

Modify an element’s style

element.style.color = 'red';
element.style.left = '100px';
element.style.cssText = 'color:red;left:100px;';

Create an element

var anchor = document.createElement('a');

Add an element to another element

someElement.appendChild(anotherElement);
// or..
someElement.insertBefore(secondElement, thirdElement);

Append text to an element

var textNode = document.createTextNode('some text, not markup');
someElement.appendChild(textNode);

Modify element content

element.innerHTML = 'Plain text or markup';

Create a class

var SomeClass = function(){
  console.log('this is the constructor');
};
SomeClass.prototype.someMethod = function(a, b, c){
  console.log('this is an instance method');
};
// or...
SomeClass.prototype = {
  someMethod : function(a, b, c){
    console.log('this is an instance method');
  }
};

Bind a context to a function

var obj1 = {
  name : 'bob',
  sayName : function(){
    console.log(this.name);
  }
};
var obj2 = {
  name : 'ken'
};
obj2.sayName = ob1.sayName.bind(obj2);
obj2.sayName();  // print "ken"

Listen for an event

someElement.addEventListener('event-type-as-string', function(event){
  console.log('this function will always get 1 and only 1 argument: the event');
});

Get data from a server

var xhr = new XMLHttpRequest();
xhr.addEventListener('load', function(e){
  console.log(xhr.responseText);
});
xhr.open('GET', 'path/to/somewhere');
xhr.send(null);

Simple recursion

var recurse = function(arg){
    console.log(arg);
    if(arg > 0){
     recurse(--arg);   
    }    
}
recurse(10);