Code too complex in "Set Default Parameters for Your Functions"?

Code too complex in "Set Default Parameters for Your Functions"?
0.0 0

#1

Note the code given in this problem

const increment = (function() {
  "use strict";
  return function increment(number, value = 1) {
    return number + value;
  };
})();
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns NaN

To define increment, it actually defines a function and immediately invokes it to assign the return value of this function (which is another function) to increment. What is the point of this and the difference between

const increment = function (number, value = 1) {
    return number + value;
  };
;

I have seen some posts discussing about this simpler version, but haven’t found a satisfying answer why freecodecamp use the former complex syntax, in other words, is this complex version somehow a good practice or can it guarantee or prevent something?


#2

It is strictly for the tests behind the scenes to test your solution.


#5

So you mean the outer function only pleases the test suite and we don’t need to follow it in our own codes?


#6

Yes, you are correct.


#7

OK Got it. Thank you!