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 triallindsaygoddard
Full Stack JavaScript Techdegree Student 4,752 PointsWhen I run console.log in my browser I get message undefined. Is something off with my code? The other code works fine.
Here. is my code:
alert("Hello. Thanks for visiting!"); console.log("Hello from the console."); document.write("<h1>Welcome to my web page.</h1>");
5 Answers
Steven Parker
231,269 PointsThis code looks OK, and it runs fine for me in the browser. If you are running it by typing into the browser console, it's normal for the console to show the return value of any function or expression you type in. Functions that don't return any value (like "console.log") will display "undefined" for the return value. That's normal.
If that's not it, and you're still having trouble, make a snapshot of your workspace and post the link to it here. Then we can replicate the issue exactly.
ibrahim z
1,710 PointsHi Lindsay, I know this is late but in case someone else looks: I had the same issue and it was because I had turned off user messages in Chrome. Once that's turned back on it displays properly.
Mary Barba
95 PointsHi there! How did you turn off user messages in Chrome?
Edit: I figured it out. A quick Google search led me here: "Sounds like you've either hidden JavaScript logs or specified that you only want to see Errors or Warnings. Open Chrome's Developer Tools and go to the Console tab. At the bottom you want to ensure that JavaScript is ticked and also ensure that you have "All", "Logs" or "Debug" selected."
I realized that I was only viewing "Errors Only". So, I clicked to view "Default levels".
James Croxford
12,723 PointsI'm running through these classes in Firefox, but on there, in the console menu at the top right is a button called 'Logs'. Until I pressed it, I couldn't see what I had logged to the console using the console.log command either. Perhaps that option needs to be selected on your console window in whatever browser you are using?
seth aruby
10,111 PointsLindsay, So the console.log("Hello from the console") line of your code has already executed as soon as you dimiss the alert dialog. If you're trying to run the console.log() command in the console after this then you'll have to pass it something, if you aren't passing it anything you'll get the 'undefined'.
Pablo Cafiso
4,184 PointsActually, you'll get the "undefined" anyway, regardless of what you pass. As Steven mentioned in his answer to Lindsay, functions in JavaScript might or might not return a value- in the case of the log() function, it is defined to not return a value so you'll get that "undefined". Not something you want to dig much into here- the "why" and "how" that value is returned by log() is a more advanced concept than the current lesson.
Samuel Weirton
6,945 PointsA big shout out to Mary Barba for the link! I had the same problem. It turns out I had something typed in the >>> console filter <<<, and it was preventing me from seeing "Hello from the console" in the console.