[Solved] display variable with highest rank


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:

var one = //undefined
var two = "yes121";
var three = "no";
var four = "yes";
var output;

if (one !=== undefined) output = one;
else if (two !=== undefined) output = two;
else if (three !=== undefined) output = three;
else if (four !=== undefined) output = four;

Alternatvely you could do this:

var output = one || two || three || four; 

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:

solved display variable with highest rank