> For the complete documentation index, see [llms.txt](https://javascript-1.gitbook.io/javascript/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://javascript-1.gitbook.io/javascript/iife.md).

# IIFE

Immediately Invoked Function Expression

* It is a function expression, invoked on its declaration.
* We can place all the library codes to avoid namespace collision.
* mostly used in the JavaScript libraries.
* When it is invoked all the variables and functions will be available in our local environment.
* The variables and functions cannot be accessed outside the function.
* It is an anonymous function express executed in flat or assign to any variable.
* It also increased the performance and saves some memory.

```javascript
Ex 1:
(function() {
    var name = "John Deo";
})();

Ex 2:
const person = (function() {
    function fullname() {
        return "John Deo";
    }
    return {
        fullname: fullname
    };
})();
person // { fullname: fullname }
person.fullname() // John Deo
```
