Skip to main content
TOPIC 9 OF 9 · 2 MIN READ

IIFE and Function Currying

IIFE(Immediately Invoked Function Expression) and currying are functional programming concepts. An IIFE is a function executed immediately after its declaration. Currying transforms a function with multiple arguments into a series of functions, each taking a single argument.

Key concepts

IIFE

Syntax: (function() { ... })(); Used to avoid polluting the global scope.

Currying

Breaking down a function into smaller functions that return another function. Improves reusability and composition.

Examples

IIFE:

(function() {
  let message = 'IIFE executed';
  console.log(message);
})();

Currying:

function multiply(a) {
  return function(b) {
    return a * b;
  };
}
const double = multiply(2);
console.log(double(5)); // 10

Practise it

Try these without looking back. If you can explain each one out loud, you are ready for this question.

  • Write an IIFE to initialize variables without affecting the global scope.
  • Create a curried function to calculate discounts on prices.

Summary

IIFE provides immediate execution and scope isolation, while currying enables function composition and partial application.

Stuck on this one? Talk to Sumit.

Keys: F focus mode · ← → previous / next topic · Esc leave focus