User Tools

Site Tools


programming:javascript:usage

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
programming:javascript:usage [2022/11/20 17:46] msprogramming:javascript:usage [2023/12/06 11:50] (current) ms
Line 1: Line 1:
 ====== Funktionen ====== ====== Funktionen ======
 +===== Objekte =====
 +Ein Objekt gruppiert mehrere Werte zusammen:
 +<code>
 +      const objektEins = {
 +        name: 'Hans',
 +        ['nach-name']: 'Wurst',
 +        alter: 27,
 +        geburtstag: {
 +          tag: 19,
 +          monat: 3,
 +          jahr: 1970
 +        }
 +      };
 +
 +    console.log(objektEins);
 +    console.log(objektEins.name);
 +    console.log(objektEins['nach-name']);
 +    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', nach-name: 'Wurst', alter: 27, geburtstag: {tag: 19, monat: 3, jahr: 1970}}
 +> Hans
 +> Wurst
 +> 27 
 +> {tag: 19, monat: 3, jahr: 1970}
 +> 19
 +> 3
 +> 1970
 +
 +
 +</code>
 +Neuer Wert in ein bestehendes Objekt hinzufügen:
 +<code>
 +objektEins.wohnort = 'Mainz';
 +
 +console.log(objektEins);
 +
 +> {name: 'Hans', nach-name: 'Wurst', alter: 27, geburtstag: {tag: 19, monat: 3, jahr: 1970}, wohnort: 'Mainz'}
 +> Mainz
 +</code>
 +
 +Ein Wert aus einem Objekt löschen:
 +<code>
 +delete objektEins.wohnort;
 +
 +console.log(objektEins);
 +
 +> {name: 'Hans', nach-name: 'Wurst', alter: 27, geburtstag: {tag: 19, monat: 3, jahr: 1970}}
 +</code>
 +Funktionen in Objekten -> Methoden
 +<code>
 +    const objektEins = { 
 +      name: 'Hans',
 +      alter: 27,
 +      methodeEins: function funktionEins() {
 +        console.log('Funktion im Objekt');
 +      }
 +    };
 +
 +      console.log(objektEins);
 +      console.log(objektEins.name);
 +      console.log(objektEins.alter);
 +      console.log(objektEins.methodeEins);
 +
 +      objektEins.methodeEins();
 +
 +> {name: 'Hans', alter: 27, methodeEins: ƒ}
 +> Hans
 +> 27
 +> ƒ funktionEins() {
 +        console.log('Funktion im Objekt');
 +      }
 +> Funktion im Objekt
 +</code>
 +<code>
 +console.log(typeof Math);
 +console.log(typeof Math.sin);
 +
 +> object
 +> function
 +</code>
 +
 ===== Einfache bedingte Ausdrücke ===== ===== Einfache bedingte Ausdrücke =====
 Allgemein bei return:\\ Allgemein bei return:\\
Line 34: Line 119:
 <code> <code>
 > function test_zahl(z){ return z>0 && z<11 ? z : console.log("falsch")} > function test_zahl(z){ return z>0 && z<11 ? z : console.log("falsch")}
-+
 > test_zahl(2) > test_zahl(2)
 2 2
Line 42: Line 127:
 <code> <code>
 > function test2_zahl(z){ return z>0 ? z<11 : console.log("falsch")} > function test2_zahl(z){ return z>0 ? z<11 : console.log("falsch")}
-+
 > test2_zahl(2) > test2_zahl(2)
 true true
Line 50: Line 135:
 falsch falsch
 </code> </code>
 +//expression1// ''||'' //expression2// -> oder\\
 +entspricht: //expression1// ''?'' ''true'' '':'' //expression2//
 +
 +''!'' //expression// -> nicht (negation)
programming/javascript/usage.1668962786.txt.gz · Last modified: 2023/01/11 20:30 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki