'Short way to write IF Statement + Assignment of Async Function in one line

Consider the code

let promiseEmployees;
const employeeFlag = DB.GetFromEMPDB(); // Goes to DAL and gets results


if (employeeFlag) {
    promiseEmployees = async () => {
            // Imp
            // ...
            // ...
            // ...
    };
}

Is it possible to rewrite this code in one line without writing literally the if (...) {...} ?



Solution 1:[1]

This should work the following way:

const promiseEmployees = !DB.GetFromEMPDB()
  ? undefined
  : async () => {
      // Imp
    };

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kevin Glier