4 ms·
I know this doesn't match up entirely with what you want syntax wise, but the following works and I consider it quite elegant. { let row; if (row = a
by shortercode 7y ago
I know this doesn't match up entirely with what you want syntax wise, but the following works and I consider it quite elegant.
{
let row;
if (row = await db.findOne()) {
//
}
else {
//
}
}
- ojosilva 7y agoIt's not the same. For instance, you could not use a `const` variable. Also having "phantom" scope blocks get very nasty to read once you have more involved logic, as the block itself has no implied meaning and the programmer has to walk a few lines into it to get what's going on.
- jazzyjackson 7y agoYou could always make it a labelled block statement !
- hombre_fatal 7y agoSeems like pretty trivial bikeshedding. How about just: const user = await db.findOne() if (user) ... else ... Typescript can even narrow the type to null vs. User in each branch block.
- deleted 7y ago[deleted]