# no-var

> Require `let` or `const` instead of `var`

A `var` belongs to the whole function, not to the block it's written in, and you can read it before the line that declares it. `let` and `const` are scoped to their block and can't be used before they're declared, which turns a class of silent bugs into errors.

`--fix` rewrites `var` to `let` where that can't change what the code does.

This rule is on by default in TypeScript files.

## Configure

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

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

## Examples

Reported:

```js
for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i)); // 3, 3, 3
}
```

Not reported:

```js
for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i)); // 0, 1, 2
}
```
