0

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 (...) {...} ?

2
  • 4
    That's certainly possible. But why would you want to? It most certainly wont improve readability. Commented Feb 10, 2022 at 10:51
  • 1
    What's wrong with if (DB.GetFromEMPDB()) promiseEmployees = async () => {...}? By the way, promiseEmployees won't be a promise with your code anyway, it will be an async function. (It would be a promise if you'd also call the function.) Commented Feb 10, 2022 at 11:21

1 Answer 1

3

This should work the following way:

const promiseEmployees = !DB.GetFromEMPDB()
  ? undefined
  : async () => {
      // Imp
    };
Sign up to request clarification or add additional context in comments.

2 Comments

This I know , I'm looking for a shorter way...
How much shorter do you need? You could write no code. That would be shorter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.