Created
January 6, 2017 00:42
-
-
Save adrianmcli/8a2f257f3e8a8ad87586c101e9f31277 to your computer and use it in GitHub Desktop.
A quiz on the Javascript event loop from Daniel Parker's JavaScript with Promises
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var async = true; | |
var xhr = new XMLHttpRequest(); | |
xhr.open('get', 'data.json', async); | |
xhr.send(); | |
// Create a three second delay (don't do this in real life) | |
var timestamp = Date.now() + 3000; | |
while (Date.now() < timestamp); | |
// Now that three seconds have passed, | |
// add a listener to the xhr.load and xhr.error events | |
function listener() { | |
console.log('greetings from listener'); | |
} | |
xhr.addEventListener('load', listener); | |
xhr.addEventListener('error', listener); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment