Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

charcodeat vs codepointat

/* String.charCodeAt(index) vs String.codePointAt(index) */

// Both methods return an integer representing the UTF-16 code.
'ABC'.charCodeAt(2); // → 67
'ABC'.codePointAt(2); // → 67

/* However, charCodeAt doesn't provide a full character code for 
values greater than 0xFFFF, only the first part of a surrogate pair.
This is common for emoji. */
"{horse emoji}".charCodeAt(0); // → 55357
"{horse emoji}".codePointAt(0); // → 128052

/* (Displaying emoji not currently supported
by Grepper, so use your imagination above.) */
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #charcodeat #codepointat
ADD COMMENT
Topic
Name
9+6 =