- Mastering JavaScript Functional Programming
- Federico Kereki
- 150字
- 2021-07-02 22:41:13
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!
推薦閱讀
- 數據庫系統原理及MySQL應用教程(第2版)
- SPSS數據挖掘與案例分析應用實踐
- Java應用與實戰
- ASP.NET MVC4框架揭秘
- GitLab Repository Management
- SAS數據統計分析與編程實踐
- 程序員修煉之道:通向務實的最高境界(第2版)
- R Deep Learning Cookbook
- C語言程序設計教程
- Kotlin開發教程(全2冊)
- Scratch趣味編程:陪孩子像搭積木一樣學編程
- Unity 3D腳本編程:使用C#語言開發跨平臺游戲
- Mastering Adobe Captivate 7
- Moodle 3 Administration(Third Edition)
- Oracle 12c從入門到精通(視頻教學超值版)