Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

941 B

title
title
Avoid Mutations and Side Effects Using Functional Programming

Avoid Mutations and Side Effects Using Functional Programming


Problem Explanation

Fill in the code for the function incrementer so it returns the value of the global variable fixedValue increased by one. fixedValue should not change, no matter how many times the function incrememter is called.


Hints

Hint 1

Using the increment operator (++) on fixedValue will mutate fixedValue, meaning it will no longer reference the same value it was assigned with.


Solutions

Solution 1 (Click to Show/Hide)
// the global variable
var fixedValue = 4;

function incrementer() {
  // Add your code below this line
  return fixedValue + 1;

  // Add your code above this line
}

var newValue = incrementer(); // Should equal 5
console.log(fixedValue); // Should print 4