Reputation: 10376
Let's say I'm loading a page that contains this code:
<script>
function functionAlert() {
alert(window.myProperty);
}
function functionSetProperty() {
window.myProperty = "hello!";
}
window.addEventListener('load', functionAlert, false);
functionSetProperty();
</script>
Is the race condition possible that functionAlert
gets called before functionSetProperty
, in which case the alert will show undefined
?
Upvotes: 0
Views: 788
Reputation: 168958
No, this is not possible. Browser-based JavaScript is single-threaded and blocks the browser from processing events while it is executing.
(I've seen some exceptions to this in the wild, but they've all centered around XmlHttpRequest.)
Upvotes: 3