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 trialAnja Wick
1,012 PointsDo 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.
console.log("Start");
document.write("Is it working?");
alert("Yes it is");
console.log("End");
1 Answer
Steven Parker
231,275 PointsBrowsers 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.
Anja Wick
1,012 PointsAnja Wick
1,012 PointsThank you!