Why can't I use ++ Operator in Pass Arguments to Avoid External Dependence in a Function

Tell us what’s happening:
I know this is early on so I don’t quite understand the purpose of the functional programming but so far, 3 lessons in, it sounds like the point is to have a function that doesn’t alter something outside of it. If so, why can’t I just use the increment operator ++ in my function? It still doesn’t change the global value but it’s considered wrong.

Your code so far


// the global variable
var fixedValue = 4;

// Add your code below this line
function incrementer (myValue) {
  
  return myValue +1;
  //return myValue++; is considered wrong
  //Add your code above this line
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/pass-arguments-to-avoid-external-dependence-in-a-function

It’s because the post incrmentor isn’t exactly the same as + 1. When you do return myValue++ it actually adds 1 after the return executes.
Either

myValue ++;
return myValue;

or

return ++myValue;

will work. If you want to dig into it, you can research the difference between a pre incrementor and post incrementor.

I realize that but the scope of it is still within the function and won’t alter the global variable.

It’s true that it doesn’t change the global variable. Are you expecting it to?

No I’m just curious why it fails even though it technically fulfills the requirements of the assignment and gives the correct response. Is it technically considered imperative to use ++, it’s not considered common practice in functional programming, it’s impolite, or it’s just not something the test was expecting?

Thank you for your responses by the way?

It doesn’t fulfill the requirements though. It will not return the correct value if you use a post incrementor, which is what I was originally trying to explain.

Ah, so you are right! ++MyValue works as expected though.
Thanks for your help