

## Nested Callbacks (with function)

```javascript
function execCB(name, cb) {
  console.log("enter " + name)
  setTimeout(cb, 0)
  console.log("leave " + name)
}

execCB("1", () => {
  execCB("2", () => {
    execCB("3", () => {
      throw new Error("stop here")
    })
  })
})

```

![ExecCB01](../figures/execCB_01.png "Chrome Dev Tools shows stack of async function calls")


```
enter 1
leave 1
enter 2
leave 2
enter 3
leave 3
```


### Nested Call

```javascript
function a(cb) {
  console.log("enter a")
  setTimeout(cb, 0)
  console.log("leave a"
  )
}

function b(cb) {
  console.log("enter b")
  setTimeout(cb, 0)
  console.log("leave b"
  )
}

function c(cb) {
  console.log("enter c")
  setTimeout(cb, 0)
  console.log("leave c"
  )
}

a(() => {
  b(() => {
    c(() => {
      throw new Error("stop here")
    })
  })
})
```

```javascript
function a(cb) {
  console.log("enter a")
  setTimeout(cb, 0)
  console.log("leave a"
  )
}

function b(cb) {
  console.log("enter b")
  setTimeout(cb, 0)
  console.log("leave b"
  )
}

function c(cb) {
  console.log("enter c")
  setTimeout(cb, 0)
  console.log("leave c"
  )
}

a(() => {
  b(() => {
    c(() => {
      throw new Error("stop here")
    })
  })
})
```