Skip to content

Instantly share code, notes, and snippets.

@hudidit
Last active November 4, 2018 07:14
Show Gist options
  • Save hudidit/cabe1f9d894edd7de35458656fb6531d to your computer and use it in GitHub Desktop.
Save hudidit/cabe1f9d894edd7de35458656fb6531d to your computer and use it in GitHub Desktop.
Promise vs. setTimeout JS Bin// source https://jsbin.com/cukasop
<!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>
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