Ian
Ian

Reputation: 25

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

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
}))();

Upvotes: 1

Views: 39

Answers (1)

anonDelta
anonDelta

Reputation: 57

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

Upvotes: 1

Related Questions