Empty parenthesis

Tell us what’s happening:

Why are there empty parenthesis at the end of the increment function? If you remove them console log doesn’t print so these are doing something, but what? I’ve never seen this before.

Also why is this question mixing ES6 and non-ES6 syntax. Not only is this confusing but it counter productive in a section that is suppose to be about using ES6 syntax.

Your code so far


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

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/set-default-parameters-for-your-functions

so I’m not sure who picks the answers, but the given answer in hints is a terrible example for a solution. My answer uses ES6 syntax and is much more clear.


const increment = (num1,value =1) => {
    return num1 + value;
};
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns 6

It’s an IIFE.

I believe it’s just there for the tests to be able to use the 'use strict' directive. The ES6 challenges where the tests depended on IIFEs have been updated to not use them anymore. It’s only on master and not in production on the site.

If you want to make, or suggest a change, to a guide article you can do so in the FCC repo. In fact, now that the challenge code has been updated the guide will need an update as well.