With the script
tags you have, the scripts can be loaded in parallel, but they will run in sequence (one after another), in the order in which they appear in the HTML.
So a
will be either undefined
(neither script has run) or 2
(both scripts have run), if it's really true that the first script will load slowly, since when it finishes loading, both scripts will run immediately after one another.
To avoid wondering about the timing around you typing in the console, you can do this:
<script>
var a = "initial";
console.log(a);
</script>
<script type="text/javascript" src='./sets-a-to-one.js'></script>
<script>
console.log(a);
</script>
<script type="text/javascript" src='./sets-a-to-two.js'></script>
<script>
console.log(a);
</script>
...where sets-a-to-one.js
is a = 'one';
, and sets-a-to-two.js
is a = 'two';
.
You'll reliably see:
initial
one
two
...regardless of the relative load speeds of the scripts.
Note that the async
and defer
attributes can change this behavior; see the spec for details. (Some browsers may not support them, or may support only one of them, or may have bugs in their support, FWIW.)