Question: How can this be possible:

```
var string1 = "", string2 = "";

//comparing the charCode
console.log(string1.charCodeAt(0) === string2.charCodeAt(0)); //true

//comparing the character
console.log(string1 === string2.substring(0,1));              //false

//This is giving me a headache.

```

<http://jsfiddle.net/DerekL/B9Xdk/>

If their char codes are the same in both strings, by comparing the character itself should return `true`. It is true when I put in `a` and `ab`. But when I put in these strings, it simply breaks.

Some said that it might be the encoding that is causing the problem. But since it works perfectly fine when there's only one character in the string literal, I assume encoding has nothing to do with it.

(This question addresses the core problem in my previous questions. Don't worry I deleted them already.)

Answer: 
In JavaScript, strings are treated by characters instead of bytes, but only if they can be expressed in 16-bit code points.

A majority of the characters will cause no issues, but in this case they don't "fit" and so they occupy 2 characters as far as JavaScript is concerned.

In this case you need to do:

```
string2.substring(0, 2) // ""

```

For more information on Unicode quirkiness, see [UTF-8 Everywhere](http://utf8everywhere.org/).
Substring parameters are the index where he starts, and the end, where as if you change it to substr, the parameters are index where to start and how many characters.