var x = "123";var y = "xyz";x = parseFloat(x, 10);y = parseFloat(y, 10);
Yes, I had forgotten about the parseFloat() method, perhaps because of its complexity and specificity to more sophisticated mathematical manipulations. In any case, as Ingolme explained, when making a comparison even strings are permissible.
if (isNaN(x)) alert("x is not a number");else if (isNaN(y)) alert("y is not a number");else alert(x + y);
So, why do you not use the try, throw and catch construct? My comparison, by the way, is made in just such a pattern, and it works great. You can use the same error messa