# [JavaScript] More Closure Examples

```
// Closure Example 1
let f;

const g = function () {
  const a = 23;
  f = function () {
    console.log(a * 2);
  };
};

const h = function () {
  const b = 777;
  f = function () {
    console.log(b * 2);
  };
};

g();
f();
console.dir(f);

// Re-assigning f function
h();
f();

console.dir(f);

// Example 2
const boardPassengers = function (n, wait) {
  const perGroup = n / 3;

  setTimeout(function () {
    console.log(`We are now boarding all ${n} passengers`);
    console.log(`There are 3 groupd, each with ${perGroup} passengers`);
  }, wait * 1000);

  console.log(`Will start boarding in ${wait} seconds`);
};

boardPassengers(180, 3);
```
Example 1

![closure 2.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1655866513238/oTEOVTRBj.PNG align="left")

Example 2

![closure 3.PNG](https://cdn.hashnode.com/res/hashnode/image/upload/v1655866522590/F1XWfcaGb.PNG align="left")

