C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
If 1: The two variables are considered equal with the "==" operator as the string is converted to a number.
If 2: The two variables are not equal here as they have different types. The inner block is not reached.
If 3: This evaluates to true as the two values have unequal types. This operator tests both types and values.
JavaScript program that uses equality comparisons
var text = "800";
var number = 800;
// Use type conversion with two equals.
if (text == number) {
console.log("OK");
}
// Do not allow type conversion with 3 equals.
if (text === number) {
console.log("Not reached");
}
// Use not equals with no type conversion.
if (text !== number) {
console.log("OK 2");
}
Output
OK
OK 2