Home >Web Front-end >JS Tutorial >Additional considerations for Javascript Chinese string processing_javascript tips
var strSex="Male";
In GB2312 encoding, assume that there is another variable strAxSex which is the BSTR value read from the ActiveX control, and the original value is also "Male". At this time, do it in the javascript program Compare: strSex==strAxSex is false, that is, "male"!="male".
But if you look at the expression strSex==strAxSex from VS2005 debugging, it is true. If you look closely, strSex.charCodeAt(0) and strAxSex.charCodeAt(0) are also equal, and strSex.charCodeAt(0) is equal to strAxSex.charCodeAt(0) is also equal to NaN.
Look at the vs2005 variable value prompt again, you can see strSex="□□". It turns out that the character constant is non-unicode, causing the value assigned to strSex to be different from the unicode value of "male". Try to save the js file as encoding utf-8 and run it again. Finally strSex==strAxSex is true. The program execution is consistent with the debugger and is consistent with the daily logic.