Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialRajesh Durai
5,046 PointsEither question is wrong or I'm misinterpreting this question
We're trying to function indentical() to work right? If that's the case we need the statement to evaluate to true, and that won't happen unless we use == instead of ===, isn't it? Because myUndefinedVariable == myNullVariable evaluates to true but this isnt the case when using the strict comparator? or maybe I'm not really getting the lesson... Like this,
var myUndefinedVariable;
var myNullVariable = null;
if(myNullVariable === myUndefinedVariable) {
console.log(true); /*<--This is where identical() would be*/
}
else{console.log("false")}
>false
Which means for the lesson the answer is NOT use the strict equality comparator, as identical() will only run if myNullVariable ==myUndefinedVariable and NOT if myNullVariable === myUndefinedVariable.
Btw I learnt a little javascript from codecademy but they never really got in depth like this so i'm not familiar with the undefined and null difference... Thanks...
2 Answers
James Barnett
39,199 PointsThe important thing to understand here is the difference between ==
(equality) and ===
(identity).
Equality checks if 2 values are equivalent whereas identity checks if 2 values are identical. null
and undefined
are not identical. However, they are equivalent as they are both falsey values. Much like "1"
and 1
are equivalent but not identical.
Equality determines if 2 values are equivalent using type coercion.
Rajesh Durai
5,046 PointsThat totally cleared it up. I was just really having trouble understanding the identity and equality issue! Thank you both so much!
Dino Paškvan
Courses Plus Student 44,108 PointsThe point is to invoke identical()
if the two variables are the same, but a null
value and an undefined
value are not truly equal in JavaScript. They are falsey values, so with non-strict comparisons, they're coerced into false
and as such appear to be equal.
In the case of this task, identical()
is being called even when it shouldn't be, as is the case for the two variables in the task.
The only thing this task wants you to do is to remove the standard equality operator and use the strict one instead.
Rajesh Durai
5,046 PointsRajesh Durai
5,046 PointsSorry no idea how to format this properly in code blocks...