DEV Community

[Comment from a deleted post]
Collapse
 
rezonant profile image
Liam Lake

Not so much an antipattern as a subtle bug. Another subtle bug is something like:

async function checkSomeCondition() : boolean;

if (checkSomeCondition()) ...;

Because it returned a promise and promises are truthy, the condition is always true! Watch out for this one! It can happen especially when you change a non-async function that is already used somewhere into an async one.

It's worth noting that you can await any value, if it's not a promise, the result is the value itself. For instance:

let x = 123;
console.log(await x);
// prints 123

While awaiting literally every variable is way overkill, you could use this in some cases if you are planning to change to async later in your changeset, because it will continue to work even before you change the function.