You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+17-7Lines changed: 17 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -179,26 +179,36 @@ A function is pure if the return value is only determined by its
179
179
input values, and does not produce side effects.
180
180
181
181
```js
182
-
constgreet= (name) =>'Hi, '+name
182
+
constgreet= (name) =>`Hi, ${name}`
183
183
184
184
greet('Brianne') // 'Hi, Brianne'
185
-
186
185
```
187
186
188
-
As opposed to:
187
+
As opposed to each of the following:
189
188
190
189
```js
190
+
window.name='Brianne'
191
+
192
+
constgreet= () =>`Hi, ${window.name}`
193
+
194
+
greet() // "Hi, Brianne"
195
+
```
191
196
197
+
The above example's output is based on data stored outside of the function...
198
+
199
+
```js
192
200
let greeting
193
201
194
-
constgreet= () => {
195
-
greeting ='Hi, '+window.name
202
+
constgreet= (name) => {
203
+
greeting =`Hi, ${name}`
196
204
}
197
205
198
-
greet() // "Hi, Brianne"
199
-
206
+
greet('Brianne')
207
+
greeting // "Hi, Brianne"
200
208
```
201
209
210
+
... and this one modifies state outside of the function.
211
+
202
212
## Side effects
203
213
204
214
A function or expression is said to have a side effect if apart from returning a value, it interacts with (reads from or writes to) external mutable state.
0 commit comments