In Javascript, this can actually be handled by the || which returns the first "valid" value.
var a = null; var b = "valid value"; var c = a || b;
Just keep in mind that the βfalseβ values ββare not only null , but also, for example, the empty string '' , number 0 and the boolean false . Therefore, you must be sure that you either consider those that have the same value as null , or your variables cannot take these values, because in these cases you will also get a second value:
var a = ""; var b = "valid value"; var c = a || b;
unziberla
source share