The reason it seems off is that you swapped the variable names, so they do not accurately represent the contents:
var e_to = charsetObj.forName(from); // Original encoding
var e_from = charsetObj.forName(to); // New encoding
The reason it works is because the final statement accounts for this by swapping the variables positions, so that despite their names, the code is actually doing this:
return newEncoding.decode( originalEncoding.encode(str) ).toString();
Obviously best to fix the variable names, so you are not scratching your head when you run across this code six months from now.
function convertEncoding(str, from, to) {
var charSetObj = createobject("java", "java.nio.charset.Charset");
var origEncoding = charsetObj.forName( arguments.from );
var newEncoding = charsetObj.forName( arguments.to );
return newEncoding.decode(origEncoding.encode( arguments.str )).toString();
}