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

Michael Mountain
Michael Mountain
3,022 Points

Help with Null and Udefined

var myVar;

undefined = true; 

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

the last console.log is not returning false like it is in the video. why?

4 Answers

Sander de Wijs
PLUS
Sander de Wijs
Courses Plus Student 22,267 Points

The result your are seeing is correct. There is no value defined for myVar so it is undefined. Did Jim put undefined in quotes in the video?

Then the outcome would be false because because myVar does not equal the String or word 'Undefined'. It is just the undefined value (or missing value) of the variable myVar.

I ran into this error last night myself. The missing piece is in the first console.log

=== "undefined"

var myVar;

undefined = true; 

console.log(typeof myVar === "undefined"); 
console.log(myVar === undefined);
Michael Mountain
Michael Mountain
3,022 Points

here is the video where he does it: http://teamtreehouse.com/library/javascript-foundations/variables/null-and-undefined

Sanders if the keyword undefined is = to true then myVar being undefined is not equal to to it right? isn't this what Jim is saying in the video?

Eric if i copy your code or if i copy Jim's code the both return true unlike Jims? can it be that we can no longer define the keyword undefined? even Jim says that its stupid that we can define it...?

thanks for your help

Wow...after redoing the lesson I see exactly what you are talking about. I think that I might have missed that the first time when I was going through the video.

The elimination of defining "undefined" would be the only logical answer.

I'm on the lesson right now and I have the exact same issue. It's not returning false. Jim missed something.