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 JavaScript Foundations Variables Null and Undefined

undefined = true;

Hello everybody,

During the video, Jim shows how to implement a line of code, undefined = true; , which causes the two messages in the console to say: true false. I copied everything correctly, but the messages in the console still read: true true, as if that line of code was commented out. Have any suggestions? Gabriel

3 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

Modern browsers, as per the EMCA 5 spec[1], undefined is read-only and not able to be editable. You would have to use an older browser version from probably a couple of years ago, or possibly even IE<9 for this to work as described in the video.

So that part of the video, while making a good point about not taking variable values for granted, is out of date for that particular snippet of code.

[1] Scroll to the 15.1.1 part of this section (about 15 parts down) - http://www.ecma-international.org/ecma-262/5.1/#sec-E

Thank you! That totally makes sense.

Here it is:

var myVar;

undefined = true;

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

var x = null;

if(myVar == null){ console.log("If"); } else { console.log("Else"); }