javascript / beginner
Snippet
Pfeilfunktionen
Pfeilfunktionen bieten eine kürzere Syntax für Funktionsausdrücke. Sie sind besonders nützlich für einfache, einzeilige Operationen und verhalten sich in Bezug auf das 'this'-Schlüsselwort anders als reguläre Funktionen.
snippet.js
1
2
3
const multiply = (a, b) => a * b;console.log(multiply(5, 2));
nodejs
Erklärung
1
const multiply = (a, b) => a * b;
Deklariert eine Konstante 'multiply', die zwei Parameter entgegennimmt und deren Produkt sofort zurückgibt.
2
console.log(multiply(5, 2));
Ruft die Pfeilfunktion auf und gibt das Ergebnis (10) in der Konsole aus.