“Anonyme Funktionen JavaScript” Code-Antworten

Anonyme Funktionen JavaScript

/*
Anonymous function = a function that doesn't need a name, you only need it for the 
purpose of a single callback
*/

// e.g.

const arr = [1,2,3,4]
arr.map(function square(num){
	return num * 2
})

// the 'square' function is only used within .map here. So it can be treated as an 
// anonymous function. Short hand for an anonymous function can look like this:

arr.map(function(num){
	return num * 2
})

// Or using arrow notation it can look like this:

arr.map((num) => {
	return num * 2
})
QuietHumility

JS Anonyme Funktion ES6

// (param1, param2, paramN) => expression

// ES5
var multiplyES5 = function(x, y) {
  return x * y;
};

// ES6
const multiplyES6 = (x, y) => { return x * y };
Adorable Anteater

Anonyme Funktionen in JavaScript

let text = function () {  
    console.log('Hello World');  
};  

text();
Gorgeous Gazelle

Anonyme Funktionsparameter JavaScript

function caller(otherFunction) {
     otherFunction(2);
 }
caller(function(x) {
    console.log(x); 
});
Blue Bison

Ähnliche Antworten wie “Anonyme Funktionen JavaScript”

Fragen ähnlich wie “Anonyme Funktionen JavaScript”

Weitere verwandte Antworten zu “Anonyme Funktionen JavaScript” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen