箭头函数(1):最简单的箭头函数

参数

单个参数

let breakfast = dessert => dessert;
  1. let 函数名 = 参数 => 函数的返回值
  2. 只有一个参数的时候可以不用加括号。
  3. 箭头函数会自动返回单行主体的结果不用加return。

多个参数

使用括号把参数扩起来。

let breakfast = (dessert,drink) => dessert + drink;

没有参数

如果没有参数,就使用空白的括号()

主体

单行主体

箭头函数会自动返回单行主体的结果,不用加return

多行主体

如果函数不是简单的返回一些东西,那就加上大括号{ },在大括号里面写函数要做的事。

猜你喜欢

转载自www.cnblogs.com/cnyaokai/p/jian-tou-han-shu-1-zui-jian-dan-de-jian-tou-han-sh.html