JSFiddle - React, Tailwind, and code Playground
JavaScript
console.log("".length); // 2
console.log("".charCodeAt(0)); // 56128
console.log("".charCodeAt(1)); // 56321
// 56128 56321 is
// http://www.fileformat.info/info/unicode/char/e0001/index.htm
// http://stackoverflow.com/questions/7126384
console.log("\uDB40\uDC01" === ""); // true
console.log(String.fromCharCode(0xDB40, 0xDC01) === ""); // true
// http://stackoverflow.com/questions/4877326
var getNumCodePoints = function(str) {
var numCodePoints = 0;
for (var i = 0; i < str.length; i++) {
var charCode = str.charCodeAt(i);
if ((charCode & 0xF800) == 0xD800) {
i++;
}
numCodePoints++;
}
return numCodePoints;
};
console.log(getNumCodePoints("")); // 1