Set Default Parameters for Your Functions : function inside parenthses?

Set Default Parameters for Your Functions : function inside parenthses?
0

#1

Tell us what’s happening:

i really don’t understand why we put all of the function inside a parentheses than we call the function with an empty parentheses ???

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 NaN

Your browser information:

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

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


#2

That is called an IIFE or Immediately Invoked Function Expression. It is an advanced technique - I’m not sure why it is here. There are some issues with the curriculum like this that are being slowly addressed.