Thanks! This article helps!
It’ll be either because both have to be in common type before comparison. That doesn’t mean a or b looses it’s datatype . The conversion is only to effect symmetric comparison. Have a look at this link for more details regarding equality algorithms
developer::mozilla::Equality_comparisons_and_sameness
Thanks and I am glad it was helpful.
== compares the values but the === compares the types. in this case one is a number and the other a string
Welcome to the forums!
In this very simplified explanation, I’d just like to note that ===
compares both type and values, not just data type.
Hi. I don’t know if this is related to this forum, but why are there parentheses around the comparison statement in the example on slide 4/11 in beginner JavaScript, Conditional Statements lessons?
This was the example:
if (hungerLevel > 7) { console.log(‘Time to eat!’); }
I wrote the statement without parentheses.
The correct syntax for conditional statements in JS is:
if (condition1) {
doThis();
} else if (condition2) {
doThat();
} else {
doThisThat();
}
This was exactly what I needed!
Wow that was just really helpful. Thanks for sharing it.
when you use ==
operator you wanna say if the values of operand(both side) were equal , return true
no matter their type is equal or not . so this expression "1" == 1
would be true .
but in some cases we want to check if the values and the types were equal , then return true .
so "1" === 1
would be false . and 1 === 1 would be true
more examples :
console.log(1 == '1') // true
console.log(""==0) // true . because string with no value always equal to 0
So this means that the === compares both the variable, as well as the data type?
If by variable you mean value, yes.
Thanks much, perfectly explained!
This article is extremely helpfull and easy to understand, thanks for sharing!
I think that is good idea to write in English, otherwise we will not be able to understand you and help you.
Can you please explain why 1 == true is true?
console.log(1 == true) // output: true
0 and 1 are type ‘number’ but in a Boolean expression, 0 casts to false and 1 casts to true
It has also to do with the double ==
as opposed to triple ===
, the latter of which is strict while the other is loose and coerces a boolean from the numbers.
1 == true // true => coercive
1 === true // false => non-coercive
Great. Thanks! Awesome explanation.
Really not that hard, but some mystery makes us demotivate! thank you for so helpful info