tc39 / proposal-do-expressions

Proposal for `do` expressions
MIT License
1.11k stars 14 forks source link

What will happen when control flow changes when a variable is init? #65

Closed Jack-Works closed 3 years ago

Jack-Works commented 3 years ago
function x(obj) {
    obj.y = () => y
    const y = do {
        if (true) return 0
        1
    }
}

const y = {}
x(y) // 0
x.y() // ?
bakkot commented 3 years ago

It would throw, because y has not been initialized.

Jack-Works commented 3 years ago

Thanks. cc @kingwl

Kingwl commented 3 years ago

because y has not been initialized.

Is that means the expression of return statement will be ignored?

Sorry I have some misunderstanding. It's might related/duplicated with #30