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 trialremovejackdonley
2,829 Pointsundefined = 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
28,690 PointsModern 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.
Sean T. Unwin
28,690 PointsPlease post your code.
removejackdonley
2,829 PointsHere 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"); }
removejackdonley
2,829 Pointsremovejackdonley
2,829 PointsThank you! That totally makes sense.