Alexander Mills Alexander Mills - 5 months ago 22
Javascript Question

Logical reduction to one line of code

Ok so my brain is a little fried after a long day of coding, but this one seems to be real. How can I reduce this to one if statement?

let combined = true;

combined = self.allChildBlocksCompleted;

if (self.parent && combined) { // i want to put everything here


is this correct?

if(self.parent || (earlyCallback && self.allChildBlocksCompleted)){


lol my brain is dead. I think it's right but I can't tell right now.

Answer Source

I prefer do it like below:

if (self.parent && (earlyCallback ? self.allChildBlocksCompleted : true )) { }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download