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!

spot_img

Subscribe

Related articles

How to get million views on youtube?

To get a million views on YouTube, you will...

Can I create a custom dashboard in react?

Yes, you can create a custom dashboard in React....

All You Need to Know About Xbox 360 Backward Compatibility

The Xbox 360 works well with some games that...

How to Check if an Array has More than One Element in PHP?

An array is a group of data structures. In...

Learn How to Select All in VIM?

Now is the time to improve your VIM skills...
spot_img
Peter Graham
Peter Grahamhttps://fix-iphones.com
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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here