function strLength(s, bUnicode255For1) { len = s.length if (bUnicode255For1) return len for (letter of s) { if (letter.charCodeAt() > 255) { len++ } } return len } console.log(strLength('hello world, 牛客', false))