How can i get the var output to display a var one OR two OR three Or four depending on rank order (highest “one” lowest “four”) and not including undefined. for eg
var one = //undefined
var two = "yes121";
var three = "no";
var four = "yes";
var output = // should be "yes121" as `var two` has the higest rank that is not undefined.
I had output as var output = one + two + three + four; but for obvious reasons that is unnecessary for what I am asking.
Clarify
if i have four variables “one” “two” “three” and “four” how can i get the output variable to be set as the highest ranked variable which is “one” (and the lowest being “four”) excluding lower ranked variables and higher ranked variables that are undefined.
Do I understand you correctly: you want to return the variable who’s NAME is closest to zero ignoring variables whos VALUE is undefined?
The only way to do that is test them one by one for not being undefined:
Alternatvely you could do this:
This can cause problems with falsy expressions though. (like ”, 0, -1, NaN, etc)
However: I think what’s you should do it create an array, so you can loop through it: