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.


Anja Wick
Anja Wick
1,012 Points

Do statements run one after the other?

I wrote this little program and when I open the page it shows me the alert message first and after closing it the content of document.write appears. I thought that if statements run one after the other, I should see "Is it working?" first and then the alert message.

Could someone explain this to me? Thank you.

document.write("Is it working?");
alert("Yes it is");

1 Answer

Steven Parker
Steven Parker
216,175 Points

Browsers don't actually render anything written to the page until the script code finshes. So the statement is executed in order, but the results of it aren't seen until the end. This is a recent behavior change, and old browsers did render on the fly.