Javascript

General

Great free courses

http://www.codecademy.com (easy, starts from zero) (Javascript, Ruby, Python)
http://code.google.com/intl/nl-BE/edu/ (more complicated)

JavaScript common

User interaction

alert
prompt

Data types

String, Number, Boolean, Undefined, Null
Arrays: var manyThings = ["peanut butter", 1972, "Teletubby", 13.2];
var data = [];
Add manually: data.push("Kiwi");
'typeof variablename' shows the type.
Eg. check if something is undefined: if (typeof Test === "undefined") …

'Falsy' values

Falsy values are values that evaluate to false.
Falsy values are: false, null, undefined, 0, "" (the empty string), and NaN.

Ternary operator

condition ? result1 : result2;

String operators

string.length: returns the length of string
string.substring(x): returns the substring of string starting at position x (first position = 0)
string.substring(x, y): returns the substring of string starting at position x till position y
string.indexOf(string2): returns the position of string2 in string
string.lastIndexOf(string2): returns the last position of string2 in string.

Conversions

parseFloat
parseInt
String(x1)

Functions

var calculateTotal = function(raceTimes) {
    ...
};

Classes

var comedy = {
  test01: function() {
  ...
  },
  test02: function() {
  ...
  }
};

Timers

setTimeout

Schedules the execution after every delay microseconds.
setTimeout(func|code, delay)

setInterval

Schedules the repeating execution after every delay microseconds.
setInterval(func|code, delay)

JavaScript DOM

Writing to the page

document.getElementById("result").innerHTML = 'Hello world!";

Get the URL

http://css-tricks.com/example/index.html?id=466&aid=32178
window.location.protocol = "http"
window.location.host = "css-tricks.com"
window.location.pathname = "example/index.html"
window.location.search = "?id=466&aid=32178"

Change the URL

window.location.href = "http://site.com/new_url";

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License