mardi 28 novembre 2017

Dynamically constructed if statement in one string variable

I am blacking out over issue and I am convinced I am thinking too complex about this, but summarized, my issue is about this:

// imagine this variable is dynamically filled by a loop with conditions inside
var condition = varA + " == " + varB + " && " + varC + " == " + varD;

if (condition) {
    // something
}

So it doesn't check whether varA equals varB and varC equals varD as what I intended, but instead it just sees it as a string and that appears to be always true anyway. I don't want, I want to see it actually checking whether varA equals varB etc.

Is there a way to parse this statement into something that actually can be a 'legit' if condition?

Thanks!

Aucun commentaire:

Enregistrer un commentaire