- 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!
推薦閱讀
- iOS Game Programming Cookbook
- Objective-C Memory Management Essentials
- Angular UI Development with PrimeNG
- Oracle從新手到高手
- 計算機圖形學編程(使用OpenGL和C++)(第2版)
- Visual Basic程序設計(第3版):學習指導與練習
- 編寫高質量代碼:改善Python程序的91個建議
- Python應用輕松入門
- Bootstrap 4:Responsive Web Design
- MATLAB 2020從入門到精通
- ArcGIS for Desktop Cookbook
- Processing創意編程指南
- Mastering AWS Security
- QGIS 2 Cookbook
- Web Developer's Reference Guide