JavaScript Basics
May 21, 2014
Kurzuebersicht zu JS-Grundlagen: Operatoren, Funktionen, Scope, Typen.
Vergleichsoperatoren
code
> < >= <= === !==
=== vergleicht Wert und Typ.
Logische Operatoren
&&und||oder!nicht
Modulo
% liefert den Rest einer Division.
Funktionen
code
const fn = function (param) {
return param;
};
Scope (global vs. lokal)
code
const globalVar = "hello";
function foo() {
const localVar = "hi";
console.log(globalVar);
}
localVar ist nur in foo sichtbar.
null / undefined / NaN
null: absichtlich leerundefined: nicht gesetztNaN: "not a number"
Increment/Decrement
code
i++;
i += 3;
i--;
i -= 2;
Strings
code
str.length;
str.indexOf("a");
str.charAt(2);
str.slice(0, 3);
Arrays und Objekte
code
const mix = [42, true, "towel"];
const obj = { key: "value" };
HTTP Status (Kurz)
2xxok3xxredirect4xxclient error5xxserver error