Add example of arrow function with no brackets (#23557)

* Add example of arrow function with no brackets

Add an example of the shorter option of an arrow function

* Fixed typo
This commit is contained in:
adrianchavez123
2018-11-26 02:20:59 -06:00
committed by Manish Giri
parent 723fbdc903
commit 2b265e3404

View File

@ -47,6 +47,14 @@ let newOneWithOneParam = a => {
} }
``` ```
When there is only one statement or operation in the function body, braces are optional and the result is returned or undefined.
```javascript
let a = 10;
let newOneParamWithNoBrackets = b => a + b;
console.log(newOneParamWithNoBrackets(20)); // 30
```
An incredible advantage of the arrows function is that you can not rebind an arrow function. It will always be called with the context in which it was defined. Just use a normal function. An incredible advantage of the arrows function is that you can not rebind an arrow function. It will always be called with the context in which it was defined. Just use a normal function.
```javascript ```javascript
// Old Syntax // Old Syntax