So today I encountered this scenario. I had an integer and a string I needed to compare. In order to compare the two I would either have to toString() the integer, or parse the string to an int.
Here's my question, which one should I go for, is there any difference in performance for the two? (even if it is minimal) Is there a rule of thumb?
Here's a code example:
var intI = 1;
var stringS = '1';
if (intI.toString() == stringS)
console.log('are equal');
//Or
if (intI == parseInt(stringS))
console.log('are equal');
It would be best if I could declare the Integer as a string I know (as it is not used for calculations). But it is used everywhere on the site.