Perform
Normally, JavaScript is executed from top to bottom as an explanatory script, but JavaScript also allows nesting in its statements, which is this:
document.write ("<script>alert (t); </SCR" + "ipt>");
Note that:</script> cannot write </script>, it is to be expressed in the form of string concatenation, or there will be grammatical errors, presumably because JavaScript encounters </script> thinks the script is over.
In this case, the order in which the normal scripts and embedded scripts are executed needs to be studied.
b.js:[DOWNLOAD]
Alert ("5");
a.js:[DOWNLOAD]
Alert ("4");
document.write ("<script src=b.js></scr" + "ipt>");
Alert ("6");
test.html:[DOWNLOAD]
<script src=a.js></script>
<script>
Alert ("1");
document.write ("<script src=b.js></scr" + "ipt>");
document.write ("<script>alert (" 3 ") </scr" + "ipt>");
Alert ("2");
</script>
To perform test.html, you can see the order in which the prints are: 4,6,5,1,3,2,5
can also do some related tests, concluded that:
1. Different code blocks of the same level, the order of execution between code blocks is from top to bottom;
2. In the case of embedding code in the code, execute the upper-layer code block, then execute the child code block; The embedded code in the code refers to the introduction of a file into another file, rather than all the code that is typed in document.write form.