JavaScripts equals what? — The differences between == and ===
For most of us the concept of an equals sign is simple, we are creating a variable that will represent a value we can refer to for use throughout our program. With this information we can understand the importance of a single equal signs but what about when we are using a double or even triple equals sign, what then?
Well for starters we need to understand the main differences between each sign, a double equals tests loose equality (It enables us to compare two or more operators by first converting their value to a common form and then checking for their equality) in layman’s terms javascript converts both values for us and checks for a common ground between the two. We can see this in the example below. Even though “2021" is in a string javascript still recognizes it as true because it takes the value of the string and recognizes the value inside is still the same.
Get Elvis Landi’s stories in your inbox
Join Medium for free to get updates from this writer.
Three equal signs is a lot easier to understand because all we really need to know is by using three equal signs you are telling javascript i am looking for the same exact value as the one i stated. JavaScript recognizes three equal signs as a strict equality which means it looks for the same type and value as the one given and if it doesn’t match up with the initial value it will return false. Due to being a strict equality most programmers prefer the three quotes especially when we are looking for an exact value. We use them in if statements, incrementing, and many more which is why it’s important to distinguish between two and three equal signs.
As a new student of JavaScript it’s a lot to take in coming from ruby so i felt it was important to share a little bit of info regarding an issue we will all encounter at some point. Knowing the differences between == and === could literally save your life (as see above). So next time you decide to slap that equal sign on your code you’ll thank me because you now know the difference between both.







