Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated arrow functions #659

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions docs/arrow-functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,30 @@ var foo = () => ({
bar: 123
});
```

### Tip: Quick value return

You might want to return value from `variables` or `functions` using the arrow function. Consider the snippet below which generates random numbers:

```ts
var random = () => Math.random();
```

> This is short form of 💡:

```ts
var random = () => {
return Math.random();
}
```
While it is possible that you can also use this while working with `arrays` and `strings`;

```ts
const str = ['a', 'b', 'c', 'd', 'e'];
const desc = () => str.reverse(); //['e', 'd', 'c', 'b', 'a']
```
in some cases, you might just want to return the value of a `variable`:
```ts
const fruits = ["Banana", "Orange", "Apple", "Mango"];
const arrFruits = () => fruits;
```