Skip to content

Instantly share code, notes, and snippets.

@jmaicaaan
Created September 30, 2021 14:21
Show Gist options
  • Select an option

  • Save jmaicaaan/45bc11b86253267b88e6c0215bb1f150 to your computer and use it in GitHub Desktop.

Select an option

Save jmaicaaan/45bc11b86253267b88e6c0215bb1f150 to your computer and use it in GitHub Desktop.
let y = 3;
/**
* The `sum` function is accessing the global variable `y` to compute for the sum
*/
const sum = (x) => x + y;
/**
* Here we are mutating the state of the variable `y` to `6`
* which means that the computation of `sum` will now be different
* This makes the `sum` function harder to understand and predict
*/
y = 6
const six = sum(3);
console.log('six', six); // 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment