- 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!
推薦閱讀
- 一步一步學Spring Boot 2:微服務項目實戰
- 程序設計與實踐(VB.NET)
- vSphere High Performance Cookbook
- Mastering Python Scripting for System Administrators
- Python Tools for Visual Studio
- HTML5+CSS3+JavaScript Web開發案例教程(在線實訓版)
- 從Excel到Python:用Python輕松處理Excel數據(第2版)
- 劍指Java:核心原理與應用實踐
- Visual C++開發入行真功夫
- Scala Reactive Programming
- Programming with CodeIgniterMVC
- Python 3.7從入門到精通(視頻教學版)
- Python從入門到精通(第3版)
- Illustrator CS6設計與應用任務教程
- Python開發基礎