diff --git a/readme.md b/readme.md index 7a28a12..7b91f4a 100644 --- a/readme.md +++ b/readme.md @@ -182,23 +182,35 @@ input values, and does not produce side effects. const greet = (name) => 'Hi, ' + name greet('Brianne') // 'Hi, Brianne' - ``` -As opposed to: +As opposed to each of the following: ```js - -let greeting +window.name = 'Brianne' const greet = () => { - greeting = 'Hi, ' + window.name + return 'Hi, ' + window.name } greet() // "Hi, Brianne" - ``` +The above example's output is based on data stored outside of the function... + +```js +let greeting + +const greet = (name) => { + greeting = 'Hi, ' + name +} + +greet() +greeting // "Hi, Brianne" +``` + +... and this one modifies state outside of the function. + ## Side effects 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.