Oracle NVL function equivalent in JavaScript/jQuery
Ternary operator typically is used here.
For example, if you're creating a dynamic action in Apex you can do something like this:
( $v("P1_VAL1") ? $v("P1_VAL1") : $v("P1_VAL2") )
This will return the value of P1_VAL1
if it's not blank, otherwise it will return the value of P1_VAL2
.
In Javascript this can actually be handled by the ||
operator, that returns the first "valid" value.
var a = null;
var b = "valid value";
var c = a || b; // c == "valid value"
Just keep in mind that "falsy" values are not only null
but also for example empty string ''
, number 0
and boolean value false
. So you need to be sure that either you consider those with the same meaning as null
or your variables cannot assume those values, because in those cases you will also get the second value selected:
var a = "";
var b = "valid value";
var c = a || b; // c == "valid value"