Tell us what’s happening:
i just have a quick question about the examples in this section. it says:
1 != 2 // true
1 != "1" // false
1 != '1' // false
1 != true // false
0 != false // false
my question is about the last 2 examples, shouldn’t 1 != true and 0 != false both return true? thanks
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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
.
Challenge: Comparison with the Inequality Operator
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
You may be forgetting that !=
means does not equal.
I’m not sure if you’ve seen the truthy/falsy lesson yet, but essentially 1==true
would be correct, but 1===true
would be false, or incorrect.
So, 1 != true
is false, and 1 !== true
is true.
1 Like
ILM
September 30, 2020, 9:20pm
3
shearmanl70:
1 != true
this is false, and 1 == true
is true because converting true
to a number, makes it a 1
when you use the not-strict-equality or disequality symbols, there is type conversion involved, and stuff is converted from a type to an other, so strings to numbers, boolean to numbers, etc
1 Like