---
# Don't modify this file manually. This file is auto generated from source, and you will lose your changes next time the website is built.
# Head to the `biomejs/biome` repository, and modify the source code in there.

title: noAssignInExpressions
description: Learn more about noAssignInExpressions
---
import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs>
<TabItem label="JavaScript (and super languages)" icon="seti:javascript">
## Summary
- Rule available since: `v1.0.0`
- Diagnostic Category: [`lint/suspicious/noAssignInExpressions`](/reference/diagnostics#diagnostic-category)
- This rule is **recommended**, meaning it is enabled by default.
- This rule doesn't have a fix.
- The default severity of this rule is [**error**](/reference/diagnostics#error).
- Sources: 
  - Inspired from [`no-cond-assign`](https://eslint.org/docs/latest/rules/no-cond-assign)

## How to configure
```json title="biome.json"
{
	"linter": {
		"rules": {
			"suspicious": {
				"noAssignInExpressions": "error"
			}
		}
	}
}

```
## Description
Disallow assignments in expressions.

In expressions, it is common to mistype a comparison operator (such as `==`) as an assignment operator (such as `=`).
Moreover, the use of assignments in expressions is confusing.
Indeed, expressions are often considered as side-effect free.

## Examples

### Invalid

```ts
let a, b;
a = (b = 1) + 1;
```

<pre class="language-text"><code class="language-text">code-block.ts:2:6 <a href="https://biomejs.dev/linter/rules/no-assign-in-expressions">lint/suspicious/noAssignInExpressions</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">The </span><span style="color: Tomato;"><strong>assignment</strong></span><span style="color: Tomato;"> should not be in an </span><span style="color: Tomato;"><strong>expression</strong></span><span style="color: Tomato;">.</span><br />  <br />    <strong>1 │ </strong>let a, b;<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>a = (b = 1) + 1;<br />   <strong>   │ </strong>     <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>3 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The use of assignments in expressions is confusing.<br /></span>    <span style="color: lightgreen;">Expressions are often considered as side-effect free.</span><br />  <br /></code></pre>

```ts
let a;
if (a = 1) {
}
```

<pre class="language-text"><code class="language-text">code-block.ts:2:5 <a href="https://biomejs.dev/linter/rules/no-assign-in-expressions">lint/suspicious/noAssignInExpressions</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">The </span><span style="color: Tomato;"><strong>assignment</strong></span><span style="color: Tomato;"> should not be in an </span><span style="color: Tomato;"><strong>expression</strong></span><span style="color: Tomato;">.</span><br />  <br />    <strong>1 │ </strong>let a;<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>if (a = 1) &#123;<br />   <strong>   │ </strong>    <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>3 │ </strong>&#125;<br />    <strong>4 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The use of assignments in expressions is confusing.<br /></span>    <span style="color: lightgreen;">Expressions are often considered as side-effect free.</span><br />  <br /></code></pre>

```ts
function f(a) {
    return a = 1;
}
```

<pre class="language-text"><code class="language-text">code-block.ts:2:12 <a href="https://biomejs.dev/linter/rules/no-assign-in-expressions">lint/suspicious/noAssignInExpressions</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br />  <strong><span style="color: Tomato;">✖</span></strong> <span style="color: Tomato;">The </span><span style="color: Tomato;"><strong>assignment</strong></span><span style="color: Tomato;"> should not be in an </span><span style="color: Tomato;"><strong>expression</strong></span><span style="color: Tomato;">.</span><br />  <br />    <strong>1 │ </strong>function f(a) &#123;<br />  <strong><span style="color: Tomato;">&gt;</span></strong> <strong>2 │ </strong>    return a = 1;<br />   <strong>   │ </strong>           <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br />    <strong>3 │ </strong>&#125;<br />    <strong>4 │ </strong><br />  <br />  <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The use of assignments in expressions is confusing.<br /></span>    <span style="color: lightgreen;">Expressions are often considered as side-effect free.</span><br />  <br /></code></pre>

### Valid

```ts
let a;
a = 1;
```

## Related links

- [Disable a rule](/linter/#disable-a-rule)
- [Configure the code fix](/linter#configure-the-code-fix)
- [Rule options](/linter/#rule-options)
- [Source Code](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/src/lint/suspicious/no_assign_in_expressions.rs)
- [Test Cases](https://github.com/biomejs/biome/blob/main/crates/biome_js_analyze/tests/specs/suspicious/noAssignInExpressions)

</TabItem>
</Tabs>