Home > Net >  Looking for an explanation on the purpose of making a function like this in js
Looking for an explanation on the purpose of making a function like this in js

Time:06-23

I tried to search for an answer but without even knowing what this is called, not really sure what to search for. I am curious as to the full purpose of using a function like this. I know the fat arrow part of it is an anonymous function.

((() => {
    // code
}))();

CodePudding user response:

It's called Immediately Invoked Function Expression, or IIFE in short. It's mostly used to avoid polluting the global namespace. You can read more about it here: https://developer.mozilla.org/en-US/docs/Glossary/IIFE

  • Related