Computer scienceProgramming languagesJavaScriptBasicsFunctions

Self-invoking functions and closures

Creating adder function

Report a typo

Write the line of code to complete the self-invoking function. This function has to log the result of addition in the console.

const adder = (function() {
  function add(a, b) {
    // missed code
  }

  return {
    add: add
  };
})();

adder.add(2, 3); // Console Output: 5
Enter a short text
___

Create a free account to access the full topic