Last active
February 8, 2023 14:02
-
-
Save caongocthai/f1516c5f32fad7b2a13963943477562f to your computer and use it in GitHub Desktop.
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
const one = () => Promise.resolve("One!") | |
var num = 1 | |
async function myFunc() { | |
console.log('Begin function') | |
const res = await one() | |
// Lines from this point onward are suspended because of await | |
// If we use one().then(res => console.log(res)), [9]console.log("End function") will not be suspended and will executed before [14] console.log("After") | |
console.log("num = ", num) | |
console.log(res) | |
console.log("End function") | |
} | |
console.log("Before") | |
myFunc() | |
console.log("After") | |
num = 5 | |
// Output: | |
// Before | |
// Begin function | |
// After | |
// num = 5 | |
// One! | |
// End function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment