Last active
November 4, 2018 07:14
-
-
Save hudidit/cabe1f9d894edd7de35458656fb6531d to your computer and use it in GitHub Desktop.
Promise vs. setTimeout JS Bin// source https://jsbin.com/cukasop
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
console.log('start'); | |
new Promise(function(resolve) { | |
console.log('promise 1'); | |
// setTimeout(function () { | |
// resolve(); | |
// }, 0); | |
resolve(); | |
}) | |
.then(function() { | |
console.log('promise 2'); | |
}) | |
.then(function() { | |
console.log('promise 3'); | |
}); | |
setTimeout(function () { | |
console.log('timeout 1'); | |
}, 0); | |
console.log('end'); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">console.log('start'); | |
new Promise(function(resolve) { | |
console.log('promise 1'); | |
// setTimeout(function () { | |
// resolve(); | |
// }, 0); | |
resolve(); | |
}) | |
.then(function() { | |
console.log('promise 2'); | |
}) | |
.then(function() { | |
console.log('promise 3'); | |
}); | |
setTimeout(function () { | |
console.log('timeout 1'); | |
}, 0); | |
console.log('end');</script></body> | |
</html> |
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
console.log('start'); | |
new Promise(function(resolve) { | |
console.log('promise 1'); | |
// setTimeout(function () { | |
// resolve(); | |
// }, 0); | |
resolve(); | |
}) | |
.then(function() { | |
console.log('promise 2'); | |
}) | |
.then(function() { | |
console.log('promise 3'); | |
}); | |
setTimeout(function () { | |
console.log('timeout 1'); | |
}, 0); | |
console.log('end'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment