Basic JavaScript - Comparison with the Inequality Operator

A question regarding the instructions, which give the following examples:
Examples

1 !=  2    // true
1 != "1"   // false
1 != '1'   // false
1 != true  // false
0 != false // false

My question is why are #4 and #5 false? 1 does not equal true, which is a true statement; 0 does not equal true, which is also a true statement.

Your code so far

// Setup
function testNotEqual(val) {
  if (val) { // Change this line
    return "Not Equal";
  }
  return "Equal";
}

testNotEqual(10);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0

Challenge: Basic JavaScript - Comparison with the Inequality Operator

Link to the challenge:

The weak comparison operator converts the two things being compared to the same type. 1 is equivalent to true and 0 is equivalent to false with this comparison

1 Like