null vs. undefinedvar a = 7; /* Number */ var b = "ahoj"; /* String */ var c = true; /* Boolean */
var d = [1, 2, 3]; /* Array */
var e = {hello:"world", foo:"bar"}; /* Object */
var f = function() {}; /* Function */
Date, RegExp, Error
if (1 > 2) { } else { }
for (var i=7; i < 8; i++) { }
while (3 < 4) { }
do { } while (3 < 4)
7 == new Number(7); "ahoj" == new String("ahoj");.toString() pro převod na řetězec"ahoj".toUpperCase(), [1, 2, 3].pop(), …Object je základní prázdná třída
var obj = {}; /* var obj = new Object(); */
obj.vlastnost = 5;
obj.metoda = function() {};
for (var p in obj) { alert(p); }
new
var mojeTrida = function() {};
var mojeInstance = new mojeTrida();
prototype
mojeTrida.prototype.metoda = function() { }
this
mojeTrida.prototype.metoda = function() {
this.vlastnost = 7;
}
window a document<input type="button" onclick="nejakaFunkce();" />
var cudlik = document.getElementById("mujButton");
cudlik.onclick = nejakaFunkce;
var cudlik = document.getElementById("mujButton");
cudlik.addEventListener("click", nejakaFunkce); /* Firefox */
cudlik.attachEvent("onclick", nejakaFunkce); /* IE */