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:
committed by
Manish Giri
parent
723fbdc903
commit
2b265e3404
@ -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.
|
||||
```javascript
|
||||
// Old Syntax
|
||||
|
Reference in New Issue
Block a user