Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript Basics Hello, JavaScript! Debug JavaScript in the Console

karan karan
seal-mask
.a{fill-rule:evenodd;}techdegree
karan karan
Web Development Techdegree Student 4,578 Points

Why 1st command no working when my 2nd command have some typo

I typed the 2nd command as it have some typo but as it should at least run the first one, but it didn't, once I fixed the problem now both are working? what can be the reason as Guil explained the 1st command runs then the 2nd.

Secondly, In the previous video Guil said, that when we write document.write() everything gets replaced by the message but over here the <h1> Tag gets added to the current page why is that?

1 Answer

Jason Larson
Jason Larson
7,539 Points

The reason the missing closing paren in the console.log line causes the previous line to not run is that the in-browser implementation of JavaScript has to parse or compile the code first (I don't know this stuff well enough to know which is the correct terminology), before it can run the individual lines of code and this line of code cause the compiler to break, so it never gets to the point of running the individual lines. Note that this would happen whether or not the console.log error was on the 2nd line, or the last line.

For the 2nd question, Guil didn't say that document.write replaces everything. He said that when we use document.write from from the console, it overwrites everything. The reason for that is that the document is closed, and when you do a document.write from the console, it opens the document, which wipes everything out, then writes to the document. When you are writing to it with the javascript the way that we are doing, the document is still open, so it performs the write operation on the document when the script is loaded.