Index

Javascript

get the type of a variable
typeof [variable]
check if variable exists
if(typeof selenium === 'undefined') {
if(typeof selenium !== 'undefined') {

arrays

initialize empty array
var a = [];
initialize array with values
var a = [ 0, 1, 2 ]

functions

defining a function
function foo() {
    alert('foo');
}

objects

// define object
var person = {
    variableA: "A",
    variableB: "B",
};
object with method
var person = {
    variableA: "A",
    nethodName : function() {
        return "hello " + this.variableA;
    }
};

control flow

iterate array
for(i=0; i<parent.length; i++) {
	Console.log(parent[i]);
}

dom

go to url
window.location = 'http://www.example.com'

delay event until user stops typing

function delay(millis, callback) {
  var timer = 0;
  return function() {
    var context = this, args = arguments;
    clearTimeout(timer);
    timer = setTimeout(function () {
      callback.apply(context, args);
    }, millis);
  };
}
example usage
document.getElementById('foo').onkeypress(delay(500, function (e) {
	alert('foo');
}));
h3 key codes for events
https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes
http://rmhh.co.uk/ascii.html
http://keycode.info/