# What's the Difference Between the Assignment (`=`) and Equality (`==`, `===`) Operators? #### Naveera A.

People who are new to programming often find it difficult to understand the difference between `=`, `==`, and `===`.

In mathematics we only use `=`, so what do the other two mean?

## The Solution

The `=` is an assignment operator, while `==` and `===` are called equality operators.

### Assignment Operator (`=`)

In mathematics and algebra, `=` is an equal to operator. In programming `=` is an assignment operator, which means that it assigns a value to a variable.

For example, the following code will store a value of `5` in the variable `x`:

```.css-8wixsa{display:block;position:relative;color:inherit;-webkit-transition:box-shadow 0.3s;transition:box-shadow 0.3s;will-change:box-shadow;outline:0;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;z-index:1;}.css-8wixsa:hover,.css-8wixsa:focus{cursor:pointer;}.css-8wixsa:hover .e1c139bc2,.css-8wixsa:focus .e1c139bc2{fill:#e1567c;cursor:pointer;}let x; // declaring a variable.

x = 5; // assigning a value of 5 to the variable.
.css-svqddq{position:absolute;z-index:10;background-color:black;float:right;top:2px;-webkit-align-self:flex-end;-ms-flex-item-align:flex-end;align-self:flex-end;color:#ffffff;display:none;}Click to Copy.css-1w9ozmm{position:absolute;z-index:10;height:20px;width:20px;fill:white;-webkit-align-self:flex-end;-ms-flex-item-align:flex-end;align-self:flex-end;background-color:black;display:block;}```

We can combine the declaration and assignment in one line:

```let y = 10;
Click to Copy```

It may look like the assignment operator works the same way as algebra’s equal to operator, but that’s not the case.

For example, the following doesn’t make any sense in algebra:

```x = x + 4;
Click to Copy```

But it is acceptable in JavaScript (and other programming languages). JavaScript will take the expression on the right-hand side of the operator `x + 4` and store this value in `x` again.

### Equality Operator (`==`)

In JavaScript, the operator that compares two values is written like this: `==`. It is called an equality operator. The equality operator is one of the many comparison operators in JavaScript that are used in logical and conditional statements.

The equality operator returns `true` or `false` based on whether the operands (the values being compared) are equal.

For example, the following code will return `false`:

```let x = 5; // declares x and assigns x to the value 5
x == 8; // returns false
Click to Copy```

Interestingly, if we compare an integer `5` and a string `"5"` it returns `true`.

```5 == "5"; // returns true
Click to Copy```

That is because in most cases, if the two operands are not of the same type, JavaScript attempts to convert them to an appropriate type for comparison. This behavior generally results in comparing the operands numerically.

### Strict Equality Operator (`===`)

Like the equality operator above, the strict equality operator compares the two values. But unlike the equality operator, the strict equality operator compares both the content and the type of the operands.

So using the strict equality operator, `5` and `"5"` are not equal.

```5 === "5"; // returns false
Click to Copy```

It is better to use the strict equality operator to prevent type conversions, which may result in unexpected bugs. But if you’re certain the types on both sides will be the same, there is no problem with using the shorter operator.