官术网_书友最值得收藏!

Returning values

In lambda style, functions only consist of a result. For the sake of brevity, the new arrow functions provide a syntax for this. When you write something like (x,y,z) => followed by an expression, a return is implied. For instance, the following two functions actually do the same as the sum3() function we showed previously:

const f1 = (x, y, z) => x + y + z;

const f2 = (x, y, z) => {
return x + y + z;
};

If you want to return an object, then you must use parentheses, or otherwise, JS will assume code is meant. 

"A matter of style: when you define an arrow function with only one parameter, you can omit the parentheses around it. For consistency, I prefer always including them. However, the formatting tool I use, prettier, doesn't approve. Feel free to choose your style!"r!

主站蜘蛛池模板: 乐山市| 台安县| 疏附县| 翁源县| 镇雄县| 浪卡子县| 安国市| 务川| 玉溪市| 芒康县| 娱乐| 新河县| 车险| 疏勒县| 黄陵县| 岳阳市| 巨野县| 法库县| 且末县| 郁南县| 公主岭市| 澜沧| 锡林郭勒盟| 磐石市| 什邡市| 芜湖市| 西吉县| 定南县| 扎囊县| 四平市| 庆云县| 深泽县| 宣城市| 盈江县| 苗栗县| 庆元县| 瑞金市| 阜新市| 凤阳县| 信丰县| 招远市|