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

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!

主站蜘蛛池模板: 拜泉县| 长春市| 卓尼县| 津市市| 祁阳县| 诸城市| 定远县| 南宫市| 驻马店市| 开原市| 土默特左旗| 同江市| 彭阳县| 沁阳市| 四平市| 会宁县| 自治县| 磐石市| 渝中区| 泾源县| 福建省| 旬阳县| 万年县| 大丰市| 峨眉山市| 肇州县| 垫江县| 大名县| 新晃| 集安市| 农安县| 如东县| 邓州市| 东兰县| 金堂县| 浦北县| 翁源县| 沙坪坝区| 乌拉特前旗| 石狮市| 富锦市|