<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [bitburner](./bitburner.md) &gt; [NS](./bitburner.ns.md) &gt; [atExit](./bitburner.ns.atexit.md)

## NS.atExit() method

Add a callback to be executed when the script dies.

**Signature:**

```typescript
atExit(f: () => void, id?: string): void;
```

## Parameters

<table><thead><tr><th>

Parameter


</th><th>

Type


</th><th>

Description


</th></tr></thead>
<tbody><tr><td>

f


</td><td>

() =&gt; void


</td><td>

A function to execute when the script dies.


</td></tr>
<tr><td>

id


</td><td>

string


</td><td>

_(Optional)_ Callback ID. Optional, defaults to `"default"`<!-- -->.


</td></tr>
</tbody></table>

**Returns:**

void

## Remarks

RAM cost: 0 GB

Each script can only register one callback per callback ID. If another callback is registered with the same callback ID the previous callback with that ID is forgotten and will not be executed when the script dies.

