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 trial

JavaScript

Null and Undefined "True True" and "True False"

<head>

    <title> JavaScript Foundations: Variables</title>
     <meta charset="utf-8">

    <style>

      html {

        background: #FAFAFA;

        font-family: sans-serif;

      }

    </style>

  </head>

  <body>

    <h1>JavaScript Foundations</h1>

    <h2>Variables</h2>


    <div id="myDiv">
      This is a div with the id of "myDiv"
    </div>

    <script src="myscript.js"></script>


  </body>

</html>
/*  JavaScript Foundations:  Variables  */

var color = "red";

var myDiv = document.getElementById('myDiv');
myDiv.style.background =  "black";
myDiv.style.color =  "#ffffff";

// Starts with A-Z a-z _ $
// Continue with A-Z a-z 0-9 _ $

// Valid Variables
var car = "Toyota";
var Color = "blue";
var _myVariable = "something";
var $specialName = 1;
var a58389 = "what is this?";

// Invalid Variable Names
// var 3colors = "red green blue";
// var winning% = 30;
// var person-name = "Jim";
// var @you = "are awesome!";

// var continue = true;/*  JavaScript Foundations:  Variables  */

var color = "red";

var myDiv = document.getElementById('myDiv');
myDiv.style.background =  "black";
myDiv.style.color =  "#ffffff";

// Starts with A-Z a-z _ $
// Continue with A-Z a-z 0-9 _ $

// Valid Variables
var car = "Toyota";
var Color = "blue";
var _myVariable = "something";
var $specialName = 1;
var a58389 = "what is this?";

// Invalid Variable Names
// var 3colors = "red green blue";
// var winning% = 30;
// var person-name = "Jim";
// var @you = "are awesome!";

// var continue = true;



var myVar;

undefined = true;

console.log(typeof myVar === "undefined");
console.log(myVar === undefined);

The result I'm expecting after refreshing is "True False" but it's staying as "True True" in Chromium.

image

In Firefox, I have no idea on how to check.

image

Jim Hoskins

Rather than posting all of this code to the forum maybe making a reduced test case using JSBin (because it has a built in console)

1 Answer

The short answer is there's a new version of JavaScript that came out (ECMA 5) since those videos were made.

For more details check out http://www.2ality.com/2013/04/check-undefined.html

You can also see Jim Hoskins' thoughts on the matter in this thread from last year