Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Foundations Variables Null and Undefined

Need help with this challenge!

I don't know what to do with this challenge. I know the identical() method it's been called out to do what?

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title> JavaScript Foundations: Variables</title>
    <style>
      html {
        background: #FAFAFA;
        font-family: sans-serif;
      }
    </style>
    <script src="ignore_this.js"></script>
  </head>
  <body>
    <h1>JavaScript Foundations</h1>
    <h2>Variables: Null and Undefined</h2>

    <div id="container">
    </div>

    <script>

        var myUndefinedVariable;
        var myNullVariable = null;

        if(myNullVariable == myUndefinedVariable) {
            identical(typeof myUndefinedVariable === "undefined");
        }

    </script>
  </body>
</html>

1 Answer

Colin Bell
Colin Bell
29,679 Points

It's just asking that you use the strict equality operator. Try using === instead of == with the original code.

if (myNullVariable === myUndefinedVariable) {
    identical();
}

This is because:

null == undefined is true

null === undefined is false

And if you're looking for things to be identical, you don't want null and undefined to be equal.