Skip to content

Commit 86d9603

Browse files
authored
Merge pull request #121 from alexlafroscia/update-purity-example
Update purity example
2 parents d1faf8b + f55916c commit 86d9603

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

readme.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -179,26 +179,36 @@ A function is pure if the return value is only determined by its
179179
input values, and does not produce side effects.
180180

181181
```js
182-
const greet = (name) => 'Hi, ' + name
182+
const greet = (name) => `Hi, ${name}`
183183

184184
greet('Brianne') // 'Hi, Brianne'
185-
186185
```
187186

188-
As opposed to:
187+
As opposed to each of the following:
189188

190189
```js
190+
window.name = 'Brianne'
191+
192+
const greet = () => `Hi, ${window.name}`
193+
194+
greet() // "Hi, Brianne"
195+
```
191196

197+
The above example's output is based on data stored outside of the function...
198+
199+
```js
192200
let greeting
193201

194-
const greet = () => {
195-
greeting = 'Hi, ' + window.name
202+
const greet = (name) => {
203+
greeting = `Hi, ${name}`
196204
}
197205

198-
greet() // "Hi, Brianne"
199-
206+
greet('Brianne')
207+
greeting // "Hi, Brianne"
200208
```
201209

210+
... and this one modifies state outside of the function.
211+
202212
## Side effects
203213

204214
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

Comments
 (0)