- 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!
推薦閱讀
- PWA入門與實踐
- 在最好的年紀學Python:小學生趣味編程
- Practical DevOps
- Vue.js 3.0源碼解析(微課視頻版)
- Java程序設計與實踐教程(第2版)
- Mastering Unity Shaders and Effects
- 小程序,巧運營:微信小程序運營招式大全
- Mathematica Data Analysis
- Python算法指南:程序員經典算法分析與實現
- 劍指大數據:企業級數據倉庫項目實戰(在線教育版)
- 21天學通C++(第5版)
- Python Essentials
- Getting Started with Nano Server
- 自學Python:編程基礎、科學計算及數據分析(第2版)
- FPGA嵌入式項目開發實戰