代码
var str = 'snowleo';
var byte = Buffer.byteLength(str);
var bf = Buffer.alloc(byte,str,'utf-8');
var consoleStr;
for(var i=0;i<bf.length;i++){
consoleStr += String.fromCharCode(bf[i]);
console.log(consoleStr);
}
直接输出String.fromCharCode(bf[0])却又正常输出‘s’,请问为什么会输出undefined?