I am new to JS, have a javascript code snippet below:
<script type="text/javascript">
var eatSteak = confirm ("Do you eat steak?");
if (eatSteak) {
document.write("Here's a Steak!");
}else{
document.write("Here's a Tofo!");
}
var happy = prompt ("Are you happy?");
</script>
When I debug the code in chrome, I see after give yes to confirm pop-up. It hits the code "document.write("Here's a Steak!");", and HTML page display "Here's a Steak!", then code hit prompt pop-up.
Very confusing for me is when I run it in chrome, "Here's a Steak!" will only display after prompt pop-up. Seems document.write only take effects after javascript code execution? Or HTML start rendering the page after javascript? I googled but cannot find a similar question or answer.