Here we go again!
This one is very easy but we all have to know it, you may already heard about it somewhere else too.
If you weren't familiar with JS's comparing way keep going. If you're then this post is not for you. 😊👏🏻
Most majority of programming languages uses
== is only comparing the value of the variable, ignoring the data type of it; so if there's a number that is equal to a number inside the string it'll always be true.
console.log('0' == 0); // Outputs: true console.log(1 == true); // Outputs: true
The data type of the variable will not be changed after the comparison
Some of Its Uses
We can use it to check if the number is not
0 or an empty string.
let num = 0;
let word = "";
console.log(num == true); // Outputs: false
console.log(word == true); // Outputs: false
num = 5;
word = "Hey!";
console.log(num == true); // Outputs: true
console.log(word == true); // Outputs: true
=== actually does is that it compares the value and the data type.
console.log("0" === 0); // Outputs: false /* They must be of the same data type. */ console.log("0" === "0"); // Outputs: true