I've written the code below to illustrate this behaviour that happens when concatting these two string.
const getBytes = x => {
let buf = Buffer.from(x);
const n = [];
for (const value of buf.values()) {
n.push(value);
}
return [n, parseInt(buf.toString('hex'), 16)];
};
let x = unescape('%uDB40');
let y = unescape('%uDD31');
console.log(typeof(x), typeof(y));
console.log(Buffer.from(x), getBytes(x), );
console.log(Buffer.from(y), getBytes(y));
console.log(Buffer.from(x+y), getBytes(x+y));
The result is:
string string
<Buffer ef bf bd> [ [ 239, 191, 189 ], 15712189 ]
<Buffer ef bf bd> [ [ 239, 191, 189 ], 15712189 ]
<Buffer f3 a0 84 b1> [ [ 243, 160, 132, 177 ], 4087383217 ]
I'm unable to understand how it ends up as a completely different result which is preventing me from successfully porting this behaviour.