Instantly share code, notes, and snippets.

Embed
What would you like to do?
JavaScript Deeper Understanding
function main(){
console.log('A');
setTimeout(
function exec(){ console.log('B'); }
, 0);
runWhileLoopForNSeconds(3);
console.log('C');
}
main();
function runWhileLoopForNSeconds(sec){
let start = Date.now(), now = start;
while (now - start < (sec*1000)) {
now = Date.now();
}
}
// Output
// A
// C
// B
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment