“Fungsi Anonim JavaScript” Kode Jawaban

Fungsi Anonim 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 Fungsi Anonim ES6

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

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

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

Fungsi anonim dalam javascript

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

text();
Gorgeous Gazelle

parameter fungsi anonim javascript

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

Jawaban yang mirip dengan “Fungsi Anonim JavaScript”

Pertanyaan yang mirip dengan “Fungsi Anonim JavaScript”

Lebih banyak jawaban terkait untuk “Fungsi Anonim JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya