- == operator
- === operator
x == y x === y
// Double Equals console.log(2 == "2"); // true console.log(0 == ""); // true console.log(null == undefined); // true console.log( == ""); // true // Triple Equals console.log(2 === "2"); // false console.log(0 === ""); // false console.log(null === undefined); // false console.log( === ""); // false
Because the "2" is changed to the number 2 before the comparison is made, the abstract equality operator for the expression 2 == "2" yields true.
Due to the various data types, the strict equality operator returns false when 2 === "2."
- To verify that two operands are equal, use the == and === operators.
- To verify the inequality of two operands, use the != and !== operators.
- The equality operators == and!= conduct type conversion on the operands before comparison since they are loose equality operators.
- Since they compare the operands without any type conversion and return false (in the case of the === operator), the stringent equality operators === and !== compare operands regardless of whether they are of the same data type.
- The == and != operators can be used to compare two operands when the data types of the operands aren't a significant component in the comparison. For instance, the database's admission numbers can be compared to the student's admission number, which was obtained through a form and may be of the string or numeric type (in number data type).
- When the data type of the operands is crucial to the comparison and cannot be changed, the === and !== operators are used to make the comparison. For instance, in a coding competition, the response could take either number or string form, but per the rules, only string-type responses will receive points. In this instance, we'll compare the user's responses to the solution kept in our database using the === operator.