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

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!

主站蜘蛛池模板: 鹰潭市| 永德县| 赞皇县| 射洪县| 开封市| 邵阳市| 盐源县| 新沂市| 吉木萨尔县| 高尔夫| 津南区| 宕昌县| 石门县| 阿荣旗| 大新县| 新建县| 陈巴尔虎旗| 越西县| 普兰店市| 罗甸县| 平泉县| 大方县| 阿尔山市| 忻城县| 古浪县| 榆树市| 淮滨县| 洛川县| 鄂托克前旗| 宁波市| 浦北县| 浦县| 体育| 神池县| 万州区| 仲巴县| 且末县| 疏附县| 西贡区| 荔波县| 孟州市|