Say I include a script at the top of an html body that doesn’t define any functions or attach any triggers to anything. It just has some plain old code like
var x = 0;
while (x < 4){
x++;
}
That’s the whole script. Despite that it doesn’t take any input or give any output, when is this executed?
Just as all other scripts, it will be executed when the HTML parser encounters the
<script>node.