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!
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 trial
Simon sCourses Plus Student 2,365 Points
Completely stuck on what to do to correct the code?
Any help on what to do the question asks 'The identical() method is being called but the variables are not identical. See if you can fix the code' any help will be appreciated.
Jessica Barnett8,028 Points
Think I have an answer for you!
You're using the double equals, but you definitely need to use the triple. That should solve your problem!
if (myNullVariable === myUndefinedVariable)
The difference between the == and the === is that the == tries to convert the two things into the same type first. So if you compare
5 == "5", you'll get true, even though one is a string and the other a number.
The === does not change the type, and only returns true if the two sides are actually the same, both in value and type. So
5 === "5" will be false, but
5 === 5 will be true.
== can work for values like numbers and strings because it's not hard to convert a "5" into a 5. But
undefined == null is the practically the same as comparing false == false. This is why you're getting true when you don't want to.
To be honest, I almost never use the double equals. If you're comparing two things, you probably want them to be the same type anyway, so you might as well.
I hope that helps!!!