# no-invalid-this

Rule `eslint/no-invalid-this`. Disallow use of `this` in contexts where the value of `this` is `undefined`

- Source: eslint
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 646.4K weekly downloads of presets that enable it
- Trend: +18.9% last quarter
- Rank: #1610 by reach, #1386 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `no-invalid-this` | no | no | package `eslint` | [docs](https://eslint.org/docs/latest/rules/no-invalid-this) |
| Biome | `nursery/noInvalidThis` | no | no | group nursery, since 2.6.0 | [docs](https://biomejs.dev/linter/rules/no-invalid-this/) |

## Code examples

### Incorrect: the rule reports this

```js
"use strict";

(function() {
    this.a = 0;
    baz(() => this);
})();

function foo() {
    this.a = 0;
    baz(() => this);
}

const bar = function() {
    this.a = 0;
    baz(() => this);
};

foo(function() {
    this.a = 0;
    baz(() => this);
});

const obj = {
    aaa: function() {
        return function foo() {
            // There is in a method `aaa`, but `foo` is not a method.
            this.a = 0;
            baz(() => this);
        };
    }
};

// …
```

### Correct: the rule accepts this

```js
"use strict";

this.a = 0;
baz(() => this);

function Foo() {
    // OK, this is in a legacy style constructor.
    this.a = 0;
    baz(() => this);
}

class Bar {
    constructor() {
        // OK, this is in a constructor.
        this.a = 0;
        baz(() => this);
    }
}

const obj = {
    foo: function foo() {
        // OK, this is in a method (this function is on object literal).
        this.a = 0;
    }
};

const obj1 = {
    foo() {
        // OK, this is in a method (this function is on object literal).
        this.a = 0;
    }
};
// …
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "no-invalid-this": "error",
    },
  },
];
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noInvalidThis": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Google](https://lintradar.dev/presets/google.md) | ESLint | `eslint-config-google` | 60 | 646.4K | +18.9% |

## Related rules

- [typescript/no-invalid-this](https://lintradar.dev/rules/typescript/no-invalid-this.md): Disallow `this` keywords outside of classes or class-like objects
- [eslint/max-depth](https://lintradar.dev/rules/eslint/max-depth.md): Enforce a maximum depth that blocks can be nested
- [eslint/max-lines](https://lintradar.dev/rules/eslint/max-lines.md): Enforce a maximum number of lines per file
- [eslint/max-params](https://lintradar.dev/rules/eslint/max-params.md): Enforce a maximum number of parameters in function definitions
- [eslint/no-implicit-coercion](https://lintradar.dev/rules/eslint/no-implicit-coercion.md): Disallow shorthand type conversions
- [eslint/capitalized-comments](https://lintradar.dev/rules/eslint/capitalized-comments.md): Enforce or disallow capitalization of the first letter of a comment

---

Web page: https://lintradar.dev/rules/eslint/no-invalid-this. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
