Difference Between =,==,=== in JavaScript Explained

When you start to learn how to program in JavaScript, you might see code that uses three different operators that look very similar.

The = (equals), == (double equals), and === (triple equals) operators are all important in JavaScript, and they all do different things. Let’s look at the difference between the JavaScript symbols =, ==, and ===.

When to Use = in JavaScript?

The Javascript operator equal (=) is very different from double equals (==) and triple equals (===). This is what is called an “assignment operator,” and it is used to give values to variables.

var primary = "Hello";

In this case, we used the = (equal) operator to give the variable primary the value “Hello.”


When to Use == in JavaScript?

Both the double equal (==) operator and the triple equal (===) operator are comparison operators in JavaScript.

The double equal (==) operator, on the other hand, is used to find abstract equality. This means that when double equal (==) is used, it first changes the types of the two values and then compares them.

The following example will evaluate to true because the double equal operator will do something called “Type Coercion” to convert both values to the same type and then compare them.

if (100 == '100') {
    //This will be equal

Your program will tell you when to use this operator. If you think that changing types will break the code, you might want to use the === operator.


When to Use === in JavaScript?

In JavaScript, the Triple Equal (===) operator is a strict comparison operator. This operator is used to compare two values while taking into account their types. If you used the first example, you’d get the opposite result.

if (100 === '100') {
    //Not considered equal

Now you know the difference between JavaScript operators “=”, “==”, and “===”. Happy coding!



Related articles

OnePlus 5T Wallpapers Download

Introduction: The OnePlus 5T is a popular smartphone known for...

Airtel’s First Quarterly Loss in 2002: A Closer Look at Jio’s Impact

The telecom industry has witnessed several significant shifts over...

Xiaomi Confirms Investment in Blackshark Gaming Phone Launch set for April 13

An engaging introduction to Xiaomi Confirms Investment in Blackshark...

LG G7 ThinQ M LCD Panel

Introduction:The LG G7 ThinQ M LCD panel is a...

Intel Core i9 Laptops with Optane Memory

Intel Core i9 laptops with Optane Memory combine the...

Apple iOS 11.4 Beta 1

Apple iOS 11.4 Beta 1 is the latest update...

Google Search AI Reorganization: Improving Search Quality and User Experience

Introduction:In the ever-evolving digital landscape, search engines play a...
Peter Graham
Peter Graham
Hi there! I'm Peter, a software engineer and tech enthusiast with over 10 years of experience in the field. I have a passion for sharing my knowledge and helping others understand the latest developments in the tech world. When I'm not coding, you can find me hiking or trying out the latest gadgets.


Please enter your comment!
Please enter your name here