# Assignment used as a condition

Source: https://findproxyforurl.net/rules/assignment-in-condition/ · last updated 2026-10-04

Rule PAC-E009 (`assignment-in-condition`), severity high, category: Errors and robustness.

A single = inside an if condition assigns instead of compares. The condition is then simply the assigned value, so the branch fires for every request.

## Why it matters

`if (host = "intranet.corp.example")` overwrites `host` and evaluates to the non-empty
string, which is truthy. Every request takes that branch. The error is invisible in a
quick read because `=` and `==` look alike. The same applies to `while` and ternary
conditions.


## How to fix

Use == (or === for strict comparison) in conditions.

## Bad

```js
function FindProxyForURL(url, host) {
  if (host = "intranet.corp.example") {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
```

## Good

```js
function FindProxyForURL(url, host) {
  if (host == "intranet.corp.example") {
    return "DIRECT";
  }
  return "PROXY proxy.corp.example:8080";
}
```
