sissonb
sissonb

Reputation: 3780

Order of Code Execution

I have the following:

HTML:

<head>

<script>
var sharedValue = {a:"b"}
</script>

<script src="otherScript.js"></script>

<script>
console.log(sharedValue);
</script>

</head>

otherScript.js

sharedValue.b = "a";

Is it possible that the console.log in the head will output {a:"b"} if otherScript.js takes too long to load? or will it always be {a:"b",b:"a"}?

Thanks!

Upvotes: 0

Views: 49

Answers (1)

Ethan Brown
Ethan Brown

Reputation: 27282

It will always be {a:"b", b:"a"}. Execution in the browser is serial and blocking.

Upvotes: 1

Related Questions