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 trialTyson Van Buren
3,692 PointsHelp!
The identical() method is being called but the variables are not identical. See if you can fix the code.
<script>
var myUndefinedVariable;
var myNullVariable = null;
if(myNullVariable == myUndefinedVariable) {
identical();
}
</script>
I'm having a really hard time solving this problem. Please help!
2 Answers
Laura Cressman
12,548 PointsHi Tyson, You just need to add an extra equals sign to the if statement. With just two equals sign, Javascript equates "null" to "undefined," because it considers null to be close enough to undefined. With three equals signs, Javascript will only return true if the two things being compared are exactly the same, not just mostly the same as is what happens when you just put two equal signs. Try this:
Hope that helps! Smile, Laura:)
var myUndefinedVariable;
var myNullVariable = null;
if(myNullVariable === myUndefinedVariable) {
identical();
}
Tyson Van Buren
3,692 PointsThanks Laura, this really helped me understand what is going on in this problem.
You rock!
Laura Cressman
12,548 PointsThank you :)