The function charCodeAttakes an index, not a string.
When you pass the string to it, it will try to convert the string to a number and use 0it if it cannot.
'1'.charCodeAt('1'). '1' . , NaN.
'f'.charCodeAt('f'). 'f' , 0, .
var hexval = result.charCodeAt(i), .
var hexval = chr.charCodeAt(0), chr.