# no-unreachable

> Disallow code after `return`, `throw`, `break`, and `continue` that can never run

Statements that follow a `return`, `throw`, `break`, or `continue` in the same block never run. Neither does code after a loop that never ends. It's either dead code you can delete, or code that was meant to run and is in the wrong place.

Function declarations and `var` declarations without a value are hoisted, so they aren't reported.

This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript finds unreachable code itself.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as a warning. To turn it off:

```toml bunfig.toml
[lint.rules]
"no-unreachable" = "off" # or "error"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
function price(item) {
  return item.price * item.quantity;
  console.log("computed", item.id);
}
```

{/* bad */}
```js
while (true) {
  poll();
}
cleanUp();
```

Not reported:

{/* good */}
```js
function price(item) {
  console.log("computing", item.id);
  return item.price * item.quantity;
}
```

{/* good */}
```js
function area(shape) {
  return width() * shape.height;

  function width() {
    return shape.width;
  }
}
```

`super()` creates a subclass's fields. If the constructor never calls it, the fields are reported:

{/* bad */}
```js
class Admin extends User {
  role = "admin";

  constructor() {
    return loadAdmin();
  }
}
```
