Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execution Order in JS Assignment Operation #95

Open
xianshenglu opened this issue Jun 10, 2019 · 0 comments
Open

Execution Order in JS Assignment Operation #95

xianshenglu opened this issue Jun 10, 2019 · 0 comments

Comments

@xianshenglu
Copy link
Owner

xianshenglu commented Jun 10, 2019

Promise.resolve().then(()=>console.log('first async task'))
var total=0
async function add(num){
    // await only delay the assignment operation
    // that's how js works in assignment
    total=(console.log('total expression before await',total)||total)+await (console.log('await expression')||num)
    console.log('assignment finished!')
}
add(1)
add(2)
setTimeout(()=>console.log(total))
Promise.resolve().then(()=>console.log('first async task'))
var total=0
async function add(num){
	// await only delay the assignment operation
	// that's how js works in assignment
	total=await (console.log('await num')||num) + (console.log('add total',total)||total)
	console.log('assignment finished!')
}
add(1)
add(2)
Promise.resolve().then(()=>{
	console.log(total)
})

https://www.cnblogs.com/xianshenglu/p/8150163.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant