These are the canonical, work-in-all-versions snippets. There are many others, most longer, some shorter (but possibly less portable).
To compare two variables as numbers ONLY, use
if (0+var1 == 0+var2)
To compare two variables as non-numeric strings ONLY, use
if ("" var1 == "" var2)