Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 33de76d

Browse files
authored
Expressions Instead of Statements
1 parent 6f3d534 commit 33de76d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

‎README.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ Arrow functions create a concise expression that encapsulates a small piece of f
99
For example:
1010

1111
```javascript
12-
// const multiply = function(x,y) {
13-
// return x * y;
14-
// }
12+
// const multiply = function(x,y) {
13+
// return x * y;
14+
// }
1515

1616
// Can be rewritten as:
1717
// const multiply = (x, y) => { return x * y };
1818

1919
// Since the function is a single expression return and braces are not needed:
2020
const multiply = (x, y) => x * y;
21-
console.log(multiply(5,10)) //50
21+
console.log(multiply(5,10)) //50
2222
```
2323

2424
<a href="https://codepen.io/Bunlong/pen/QBgdJb" target="_blank">Edit on Codepen</a>
@@ -46,11 +46,20 @@ For example:
4646
Statement
4747

4848
```javascript
49-
49+
const getSalutation = function(hour) {
50+
var salutation; // temp value
51+
if (hour < 12) {
52+
salutation = "Good Morning";
53+
} else {
54+
salutation = "Good Afternoon"
55+
}
56+
return salutation; // mutated value
57+
}
5058
```
5159

5260
Expression
5361

5462
```javascript
55-
63+
const getSalutation = (hour) => hour < 12 ? "Good Morning" : "Good Afternoon";
64+
console.log(getSalutation(10)); // Good Morning
5665
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /