programming:javascript:usage
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
programming:javascript:usage [2022/11/20 17:43] – ms | programming:javascript:usage [2023/12/06 11:50] (current) – ms | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Funktionen ====== | ====== Funktionen ====== | ||
+ | ===== Objekte ===== | ||
+ | Ein Objekt gruppiert mehrere Werte zusammen: | ||
+ | < | ||
+ | const objektEins = { | ||
+ | name: ' | ||
+ | [' | ||
+ | alter: 27, | ||
+ | geburtstag: { | ||
+ | tag: 19, | ||
+ | monat: 3, | ||
+ | jahr: 1970 | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | console.log(objektEins); | ||
+ | console.log(objektEins.name); | ||
+ | console.log(objektEins[' | ||
+ | console.log(objektEins.alter); | ||
+ | console.log(objektEins.geburtstag); | ||
+ | console.log(objektEins.geburtstag.tag); | ||
+ | console.log(objektEins.geburtstag.monat); | ||
+ | console.log(objektEins.geburtstag.jahr); | ||
+ | |||
+ | > {name: ' | ||
+ | > Hans | ||
+ | > Wurst | ||
+ | > 27 | ||
+ | > {tag: 19, monat: 3, jahr: 1970} | ||
+ | > 19 | ||
+ | > 3 | ||
+ | > 1970 | ||
+ | |||
+ | |||
+ | </ | ||
+ | Neuer Wert in ein bestehendes Objekt hinzufügen: | ||
+ | < | ||
+ | objektEins.wohnort = ' | ||
+ | |||
+ | console.log(objektEins); | ||
+ | |||
+ | > {name: ' | ||
+ | > Mainz | ||
+ | </ | ||
+ | |||
+ | Ein Wert aus einem Objekt löschen: | ||
+ | < | ||
+ | delete objektEins.wohnort; | ||
+ | |||
+ | console.log(objektEins); | ||
+ | |||
+ | > {name: ' | ||
+ | </ | ||
+ | Funktionen in Objekten -> Methoden | ||
+ | < | ||
+ | const objektEins = { | ||
+ | name: ' | ||
+ | alter: 27, | ||
+ | methodeEins: | ||
+ | console.log(' | ||
+ | } | ||
+ | }; | ||
+ | |||
+ | console.log(objektEins); | ||
+ | console.log(objektEins.name); | ||
+ | console.log(objektEins.alter); | ||
+ | console.log(objektEins.methodeEins); | ||
+ | |||
+ | objektEins.methodeEins(); | ||
+ | |||
+ | > {name: ' | ||
+ | > Hans | ||
+ | > 27 | ||
+ | > ƒ funktionEins() { | ||
+ | console.log(' | ||
+ | } | ||
+ | > Funktion im Objekt | ||
+ | </ | ||
+ | < | ||
+ | console.log(typeof Math); | ||
+ | console.log(typeof Math.sin); | ||
+ | |||
+ | > object | ||
+ | > function | ||
+ | </ | ||
+ | |||
===== Einfache bedingte Ausdrücke ===== | ===== Einfache bedingte Ausdrücke ===== | ||
Allgemein bei return:\\ | Allgemein bei return:\\ | ||
Line 32: | Line 117: | ||
// | // | ||
entspricht: // | entspricht: // | ||
+ | < | ||
+ | > function test_zahl(z){ return z>0 && z<11 ? z : console.log(" | ||
+ | |||
+ | > test_zahl(2) | ||
+ | 2 | ||
+ | > test_zahl(22) | ||
+ | falsch | ||
+ | </ | ||
+ | < | ||
+ | > function test2_zahl(z){ return z>0 ? z<11 : console.log(" | ||
+ | |||
+ | > test2_zahl(2) | ||
+ | true | ||
+ | > test2_zahl(22) | ||
+ | false | ||
+ | > test2_zahl(-2) | ||
+ | falsch | ||
+ | </ | ||
+ | // | ||
+ | entspricht: // | ||
+ | '' |
programming/javascript/usage.1668962631.txt.gz · Last modified: 2023/01/11 20:30 (external edit)