Subj : Getting string objects to compare equal To : netscape.public.mozilla.jseng From : Steve Evans Date : Tue Sep 20 2005 03:59 pm Here's a snippet of alas-all-too-common script from a website: if (theForm.frmEmail.value != theForm.frmEmailConf.value) { errAlert("The E-mail addresses entered do not match") return false } This is comparing two string *objects*, which is like comparing two C strings using == instead of strcmp(). It should always fail. One of the string objects should have been stringified with toString() to force the JS engine to do a string comparison. And yet it works in current versions of Firefox and Opera and IE, but not in my embedded SpiderMonkey environment, which fails "correctly", as per the JS spec. For a while I thought that maybe Firefox interned the values of the form controls using JS_InternString(), so that the frmEmailConf.value really does use the same JSString as frmEmail.value. However, a grep through the source reveals that JS_InternString() is only used for read-only constant strings that will really benefit from re-use: attribute names rather than attribute values. So how do I emulate Firefox's forgiving behaviour? .