You can use the Blob to get the string size in bytes.
Examples:
console.info(_x000D_
new Blob(['']).size, // 4_x000D_
new Blob(['']).size, // 4_x000D_
new Blob(['']).size, // 8_x000D_
new Blob(['']).size, // 8_x000D_
new Blob(['I\'m a string']).size, // 12_x000D_
_x000D_
// from Premasagar correction of Lauri's answer for_x000D_
// strings containing lone characters in the surrogate pair range:_x000D_
// https://stackoverflow.com/a/39488643/6225838_x000D_
new Blob([String.fromCharCode(55555)]).size, // 3_x000D_
new Blob([String.fromCharCode(55555, 57000)]).size // 4 (not 6)_x000D_
);
_x000D_