Search code examples
javascriptiife

Why use an IIFE in this situation?


In an article on browser plugin development, they use this code:

window.browser = (function () {
  return window.msBrowser ||
    window.browser ||
    window.chrome;
})();

Why would they use an IIFE rather than, say:

window.browser = window.msBrowser || window.browser || window.chrome;

Is there something that an IIFE brings to the table that I'm overlooking?


Solution

  • There's no advantage to it in that specific situation. Perhaps the code you're looking at originally had more logic which was subsequently removed.