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

JavaScript JavaScript Foundations Variables Null and Undefined

Eric Tirado
Eric Tirado
iOS Development Techdegree Student 7,036 Points

when I type undefined = true; I still get a true value on my console in google chrome.

console.log(myVar === undefined); doesn't print a false value when I type undefined = true. Why is this?

I'm actually having the same issue. Some solid feedback on this would be appreciated. Or at least a remake of this video. Something!

4 Answers

I was doing the same exercise as you, Eric (trying to determine whether I understand the material). I too was getting a different result. I decided to check MDN and other references about undefined in JavaScript.

When I read that undefined is not a writable property, it made things crystal clear (as far as how to use undefined). It fits in with what Katie stated "typing undefined = true would be ignored". Further testing has reinforced my understanding. This portion of the lesson should be redone.

Hope that helps.

UPDATE: On the MDN site, I did see an example of how undefined COULD be changed. Maybe it is something the TreeHouse team can clarify as it relates to this video and lesson.

Just wanted to add a direct link to MDN's undefined reference page:


Kate Hoferkamp
Kate Hoferkamp
5,205 Points

I'm not positive what you are trying to do either, but you cannot set undefined to be anything, ie true. Undefined is a state not a variable. So typing undefined = true would be ignored.

From what I can see Jim must have been using an older revision of JavaScript supported by his browser at the time the video was made. Checking the Mozilla Developer Network for undefined gives the explanation for this inconsistency:

In modern browsers (JavaScript 1.8.5 / Firefox 4+), undefined is a non-configurable, non-writable property per the ECMAScript 5 specification. Even when this is not the case, avoid overriding it.

I'm not sure what you're trying to do, but I'm pretty sure you're going about it the wrong way. Are you trying to test if a variable is undefined? If so, this would be the way to do it:

var myVar;
Eric Tirado
Eric Tirado
iOS Development Techdegree Student 7,036 Points

That is what I'm trying to do. Sorry. I thought this would be attached to the lesson I was taking.

This is how he does it in the example:

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


He is trying to show us that undefined is also used as a keyword rather than a string by removing the quote marks.

''' console.log(typeof myVar === undefined); ''' It works. I get it, but he shows that undefined (without quote marks) is not really a keyword but a variable defined by the javascript and that it can be tampered with by giving it a new value and it would make myVar test to false as a result rather test to true.

''' undefined = true; ''' I don't know if I'm using the markdown properly. Anyhow, I understand the principle. I just want to be able to replicate it to feel like I learned the lesson and proceed.

this is the lesson: http://teamtreehouse.com/library/javascript-foundations/variables/null-and-undefined