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 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:

http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice

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
STAFF
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.