1
New methods similar to Ecmascript 6 have been added to String.fromCharCode() and String#charCodeAt(): String.fromCodePoint() and String#codePointAt().
What’s the difference between them?
1
New methods similar to Ecmascript 6 have been added to String.fromCharCode() and String#charCodeAt(): String.fromCodePoint() and String#codePointAt().
What’s the difference between them?
0
Of documentation:
String.fromCodePoint()
The String.fromCodePoint() static method returns a string created using the specified sequence of code points
String.prototype.codePointAt()
The codePointAt() method returns a non-negative integer which is the code Unicode of the code point
Links:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/codePointAt
0
The difference is simple. First, a value of type String (most expressed as "string") stores a sequence of non-negative integer numbers, the size of 2 bytes (16 bits), called "elements" to facilitate reference.
The method String#charCodeAt(índice), for example, only returns the value of the element in index (which by convention initiates the 0) specified as a number. The static method String.fromCharCode(...códigos) returns a String type value, where each element equals each given code.
Now, the difference of String#codePointAt(índice). Based on UTF-16 encoding, returns the character code in the index (index of elements, not code) given.
The static method String.fromCodePoint(...códigos) also differentiates from String.fromCharCode() UTF-16 coding (creates two elements if you need to surrogate pairs to represent the code of a character), but finally, does not give exceptions for codes between 0xD800 and 0xDFFF (surely you should).
Browser other questions tagged javascript ecmascript-6
You are not signed in. Login or sign up in order to post.