Are They Different? == vs ===

First, let's understand what those symbols represent. These symbols are used to check whether the value on both sides is the same or not if its same returns True or if don't match false. It basically compares both values. These symbols are used in conditional statements and logic where the program has to make the decision depending on the outcome. This operator is called Equality Operator / Comparison Operator.

They do have different names:

  1. Loose Equality Operator ( == )

  2. Strict Equality Operator ( === )

Let's find the difference:

A loose Equality Operator is a normal equality operator which checks whether the value on both sides is matching or not. But it doesn't care what type of value is compared with what type. If the value matches it returns true.

How?

it implicitly changes the value to the value type which it is compared with. Example listed below

let minimumAge = 34;
let saraAge = '34';

// Variable Example
if(minimumAge == saraAge){
// The code gets Executed
console.log('True');
}

// Direct Value 
if(34 == '34'){
console.log('True');
}

Here the minimumAge is an Integer value and saraAge is a string that represents the exact value as minimumAge but in the String form. So javascript implicitly converts the string value into number and returns TRUE.

Strict Equality is something that you need to use instead of Loose. This operator doesn't convert the value even if the value matches with the other value if even check for the type if both the types match then return TRUE or if they don't FALSE

let minimumAge = 34;
let saraAge = '34';

// Variable Example
if(minimumAge === saraAge){
// The code won't get Executed
console.log('True');
}

// Direct Value 
if(34 == '34'){
console.log('True');
}

Here this returns false because the minimumAge is an Integer value and saraAge is a string. It won't perform any type of conversion.

0
Subscribe to my newsletter

Read articles from Shaik Mohammed Huzaifa directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Shaik Mohammed Huzaifa
Shaik Mohammed Huzaifa

I am a Full Stack Developer with expertise in a variety of programming languages and frameworks, including C++, Javascript, C#, C, Node.js, MySQL, MongoDB, Python, and Dart. I have extensive experience developing both web and mobile applications using frameworks and libraries such as React, React Native, Angular, and ASP.NET, among others. As a developer, I am passionate about staying up-to-date with the latest technologies and learning new programming languages, frameworks, and tools. I believe in constantly pushing the boundaries of what's possible and developing innovative solutions to real-world problems. I am committed to delivering high-quality code that is efficient, scalable, and maintainable. I am a team player who enjoys collaborating with others to achieve shared goals and objectives. I believe that effective communication, attention to detail, and a strong work ethic are essential to success in any project or organization. If you're interested in connecting with me or learning more about my work, feel free to reach out or follow me on Hashnode.