Skip to content

Instantly share code, notes, and snippets.

@Etc3tera
Created March 28, 2024 07:55
Show Gist options
  • Save Etc3tera/eeff334718adde9dd32c683a858d60e7 to your computer and use it in GitHub Desktop.
Save Etc3tera/eeff334718adde9dd32c683a858d60e7 to your computer and use it in GitHub Desktop.
explain JS single thread
message = 'aha'
setTimeout(() => {
message = 'happy';
}, 1)
setTimeout(() => {
console.log('2nd setTimeout: ' + message)
}, 500)
console.log('start: ' + new Date().toISOString())
x = 0
for(let i = 0; i < 500; i++) {
for(let j = 0; j < 1000000; j++) {
x = Math.random()
}
}
console.log('end: ' + new Date().toISOString())
console.log(message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment