I have this line of code in JS for handing payments, but I'm not sure what it's doing as I've never seen some of this syntactic sugar before.
var fund = response.card != null ? response.card[0] : response.bank_acct[0];
I have this line of code in JS for handing payments, but I'm not sure what it's doing as I've never seen some of this syntactic sugar before.
var fund = response.card != null ? response.card[0] : response.bank_acct[0];
This is the conditional operator. Instead of writing this:
var fund;
if(response.card != null )
{
fund = response.card[0]
}
else
{
fund = response.bank_acct[0];
}
you could write this:
var fund = response.card != null ? response.card[0] : response.bank_acct[0];
It works the same as (and is considered shorthand for) this conditional statement:
var fund;
if (response.card != null) {
fund = response.card[0];
} else {
fund = response.bank_acct[0];
}