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!

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


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
227,140 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.