I was also posting this in the do proposal:
tc39/proposal-do-expressions#9
To me, it sounds most logical that if any of the if, switch, for, while, try keywords are used in an expression context, then it will be an implicit do expression construction:
So the following
const num = if (cond) {
100;
} else {
10;
};
would be equivalent to:
const num = do {
if (cond) {
100;
} else {
10;
}
}
Similarly, the following
const iterable = for (let user of users) {
if (user.name.startsWith('A'))
yield user;
}
would be equivalent to
const iterable = do* {
for (let user of users) {
if (user.name.startsWith('A'))
yield user;
}
};
I was also posting this in the do proposal:
tc39/proposal-do-expressions#9
To me, it sounds most logical that if any of the
if,switch,for,while,trykeywords are used in an expression context, then it will be an implicit do expression construction:So the following
would be equivalent to:
Similarly, the following
would be equivalent to