Search code examples
javascriptecmascript-6iife

do we still use iife in es6+


so I am learning javascript and I come across the IIFE (immediately invoked function expressions)

and I don't know if we still use it in 2020 can you tell me if it useful or there is a new way to do it


Solution

  • IIFEs were often used with the Module Pattern in JS to limit what a module would expose to the caller. We now have much better options for scoping, modules and intelligent bundling of assets, so you will rarely see it used anymore.

    In my experience, it is not that we have a new way of doing it, it is just that the use-case for it has almost vanished. That being said, if you find yourself in the rare situation where it is needed, it is still perfectly valid.