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 (Retired) Introducing JavaScript Your First JavaScript Program

Is document.write worth teaching anymore?

I've come across document.write as being a controversial subject, considered "bad practice." If that were the case, is it good form to teach it anymore? Even if it is easy to use to get a concept across, isn't it taught at an opportunity cost of time that could be spent teaching something equally as effective that has a better chance of being used in good practice?

I'm basing this on the link from StackOverflow:


Notice one of the commentors said, "There's actually nothing wrong with document.write, per se. The problem is that it's really easy to misuse it."

3 Answers

Dave McFarland
Dave McFarland
Treehouse Teacher

Hi Ron,

Every JS programmer should KNOW about document.write(). I use it in my course to provide a fast and easy way to get students writing code that produces an effect you can see in a web browser.

It is true that document.write() is no longer a common way to add content to a web page, now that we have more advanced ways to manipulate a page's DOM (document object model). However those techniques require a firm foundation in JavaScript -- in fact, our Interactive Web Pages with JavaScript and jQuery Basics courses provide great instruction in those methods.

It's always a fine balance between providing information that's works and is easy for people new to programming and current professional practices (which often require more knowledge)

Hope that helps.

Louis Otto
Louis Otto
23,264 Points

Dave's answer hits the nail on the head, but I just wanted to add that it's always good to know the fundamentals. You never know when there might be limitations preventing you from using something like jQuery, in which case knowing the fundamentals can save your bacon!

Yeah, I figured that might be the case. Thanks for the response Dave. I'm loving your videos; they're good content that's easy to understand without skipping over anything.