When is the code in the dynamically created script crammed into the main thread to execute

I want to know that when spa has been loaded, I dynamically create a script, that contains a piece of code. Since I want to use the results executed in script in the code, I need to find out at which stage the code in the dynamically created script is crammed into the main thread for execution.

Dec.23,2021

Synchronize

var script = document.createElement("script");
script.innerHTML = 'console.log(1);'
document.body.appendChild(script);
console.log(2);
// 1 2

Asynchronous

var script = document.createElement("script");
script.src = 'xxx.js';//
document.body.appendChild(script);
script.onload = function() {//script 
    console.log('script load');
}

you can listen to the onload event and call it after loading and execution is complete.

var newScript = document.createElement('script')
newScript.src = 'xxx.js'
document.body.appendChild(newScript)
newScript.onload = function() {
   // 
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b34d61-2b6c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b34d61-2b6c2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?