> For the complete documentation index, see [llms.txt](https://javascriptuse.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://javascriptuse.gitbook.io/javascript/advanced/javascript-chuyen-sau-tu-ham-iife-toi-module-pattern/iife-greater-than-immediately-invoked-function-expression-greater-than-khoi-tao-function-and-chay-ng.md).

# IIFE=>Immediately Invoked Function Expression=>khởi tạo function & chạy ngay, import, export như nào

index.html

```html
<!DOCTYPE html>
<html>
<body>
  <h1>JavaScript Modules</h1>
  <script type="module" src="app.js"></script>
</body>
</html>
```

file1.js

```javascript
export const greet = (name) => {
  return `Hello, ${name}!`;
};

```

file2.js

```javascript
import { greet } from './file1.js';
const aa = (function () {
  const message1 = greet('John 2');
  return {
    message1
  }
})();
export default aa;
```

file3.js

```javascript
import { greet } from './file1.js';
import aa from "./file2.js";
const bb = (function () {
  const message2 = greet('John 3') + aa.message1;
  return {
    message2
  }
})();
export default bb;
```

app.js

```javascript
import bb from "./file3.js";
console.log(bb.message2)
```

<figure><img src="https://2726517656-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M1E4Gk2ppVKb4olmnun%2Fuploads%2F9SpcumZMGFavAx4waYNc%2Fimage.png?alt=media&amp;token=50b98ede-3d4d-44a4-9a00-0111eff6ca43" alt=""><figcaption></figcaption></figure>
