Javascript: a double function with a double return

I just started the ES6 part of things am, I’ve run across something that I don’t understand in the lesson ES6: Set Default Parameters for Your Functions.

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

I know how to answer the question, but I don’t understand this function. Why do we event need this line in there return function increment(number, value) {. I can’t tell if 2 functions are being defined or if this is something that is recursive or something else. How does the double return work?

1 Like

The outer function is an Immediately Invoked Function Expression, which returns a function - it is there for tests sake, even if technology evolves so the challenges are being changed because the tests don’t need this anymore

1 Like