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

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!

主站蜘蛛池模板: 小金县| 建德市| 西昌市| 安新县| 岐山县| 昆山市| 阿勒泰市| 清原| 永善县| 五大连池市| 连云港市| 区。| 垣曲县| 凤凰县| 荥经县| 军事| 如皋市| 莱阳市| 凤翔县| 青铜峡市| 子长县| 桦甸市| 罗田县| 基隆市| 宁河县| 霞浦县| 虞城县| 铜鼓县| 南昌县| 永泰县| 黄浦区| 伊宁县| 江达县| 交城县| 泰宁县| 琼结县| 沂源县| 永泰县| 格尔木市| 永兴县| 绥滨县|