Sometimes your asynchronous function calls another asynchronous function conditionally. Writing such code in an elegant way may take a bit of effort. Case in point: let's consider application logic, in which we cache response from an API call and therefore only make an API call if the information is stale or missing. An if statement where part of it is calling asynchronous logic and part is not can get messy. Let's see an example code where we try to untangle the complexity.
Note: this is an example code for demonstration purposes-only, it is missing trivial parts for brevity and is therefore not runnable as-is:
In summary, by introducing a variable that is assigned to the sub-call invoking a promise and turning non-async part of the if logic into a fake promise, we can make code look uniform and clean. Which is what you see in the implementation of lookupValue() function. The refreshEntity() function implementation is not directly related to the trick we are explaining, but is included here to bring more clarity to the context of the discussion.