The problem with the valueOfVar(box_split[0]+'_2') test valueOfVar(box_split[0]+'_2') is that you are adding a string to the undefined attribute. You will always pass a string to valueOfVar() with the value 'undefined_2' .
You will notice that the typeof operator will return 'string' if you try the following:
function valueOfVar(foo){ alert(typeof foo); } valueOfVar(box_split[0]+'_2');
The typeof operator will work for these types of tests, but you cannot add anything to the undefined variable, otherwise it will always check true:
if (typeof foo === 'undefined') { // foo does not exist } else { // it does }
Daniel Vassallo
source share