+ 1
Can u explain == and ===?
4 Answers
+ 7
== is called soft while === is considered as hard comparisson operator using=== is considered as best practice, at least that's what I read in the JS Ninja book.
+ 5
So, = means "Assign this value to this variable". It sets values. On the other hand, == or === mean "Check if this value is eaual to this variable". It's checking for something, or asking a question. It's more often than not in if statements. Like so:
if (name === "Athul") {
console.log("Hello, Athul!")
}
0
Beside ==, === also compares the data types.
JavaScript is intelligent and in the case of 1 == '1' it converts the string '1' into a number.
But with '===' you tell JavaScript to be more precise and you ask for an 'absolute equality'.
Hope it was useful!