JavaScript Modularization Techniques Immediately invoked function expressions (IIFE)

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Immediately invoked function expressions can be used to create a private scope while producing a public API.

var Module = (function() {
  var privateData = 1;

  return {
    getPrivateData: function() {
      return privateData;
    }
  };
})();
Module.getPrivateData(); // 1
Module.privateData; // undefined

See the Module Pattern for more details.



Got any JavaScript Question?