JavaScript:创建匿名函数

infgrad

关注

阅读 46

2022-01-17

// 将匿名函数赋值给 myFunc
const myFunc = function(param1, param2, ...) {
  // Statements using param1, param2, ...
};

// 调用匿名函数
// param1 value is set to arg1, param2 to arg2, ...
myFunc(arg1, arg2, ...);

另一种方法

const hello = (name) => {
  const message = `Hello, ${name}!`;
  return message;
};

console.log(hello("William")); // "Hello, William!"

精彩评论(0)

0 0 举报