| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt | [Back] [Original] |
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.
String charCodeAt() UTF-16 0 65535 .
charCodeAt() UTF-16 (lone surrogates) . String.prototype.codePointAt() .
const sentence = "The quick brown fox jumps over the lazy dog.";
const index = 4;
console.log(
`Character code ${sentence.charCodeAt(index)} is equal to ${sentence.charAt(
index,
)}`,
);
// Expected output: "Character code 113 is equal to q"
charCodeAt(index)
index UTF-16 0 65535 . index 0 str.length - 1 charCodeAt() NaN .
. 0 str str.length - 1.
0 1114111(0x10FFFF). 16 charCodeAt() 65536 . 65535 charCodeAt(i) charCodeAt(i + 1) ( ) codePointAt(i) . UTF-16 , .
A 65 .
"ABC".charCodeAt(0); // 65
charCodeAt() (lone surrogates) .
const str = "";
console.log(str.charCodeAt(0)); // 55362, d842
console.log(str.charCodeAt(1)); // 57271, dfb7
String.prototype.codePointAt() .
const str = "";
console.log(str.codePointAt(0)); // 134071
:
charCodeAt() codePointAt() . UTF-16 codePointAt() . codePointAt() .
FAQ UTF-16 .
// constants
const LEAD_OFFSET = 0xd800 - (0x10000 >> 10);
const SURROGATE_OFFSET = 0x10000 - (0xd800 << 10) - 0xdc00;
function utf16ToUnicode(lead, trail) {
return (lead << 10) + trail + SURROGATE_OFFSET;
}
function unicodeToUTF16(codePoint) {
const lead = LEAD_OFFSET + (codePoint >> 10);
const trail = 0xdc00 + (codePoint & 0x3ff);
return [lead, trail];
}
const str = "";
console.log(utf16ToUnicode(str.charCodeAt(0), str.charCodeAt(1))); // 134071
console.log(str.codePointAt(0)); // 134071
| Specification |
|---|
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.charcodeat |
String.fromCharCode()String.prototype.charAt()String.fromCodePoint()String.prototype.codePointAt()This page was last modified on 2025 10 9 by MDN contributors.
StringString.prototype.anchor()String.prototype.at()String.prototype.big()String.prototype.blink()String.prototype.bold()String.prototype.charAt()String.prototype.charCodeAt()String.prototype.codePointAt()String.prototype.concat()String.prototype.endsWith()String.prototype.fixed()String.prototype.fontcolor()String.prototype.fontsize()String.prototype.includes()String.prototype.indexOf()String.prototype.isWellFormed()String.prototype.italics()String.prototype.lastIndexOf()String.prototype.link()String.prototype.localeCompare()String.prototype.match()matchAll()String.prototype.normalize()String.prototype.padEnd()String.prototype.padStart()String.prototype.repeat()String.prototype.replace()String.prototype.replaceAll()String.prototype.search()String.prototype.slice()String.prototype.small()String.prototype.split()String.prototype.startsWith()String.prototype.strike()String.prototype.sub()String.prototype.substr()String.prototype.substring()String.prototype.sup()String.prototype.toLocaleLowerCase()String.prototype.toLocaleUpperCase()String.prototype.toLowerCase()String.prototype.toString()String.prototype.toUpperCase()String.prototype.toWellFormed()String.prototype.trim()String.prototype.trimEnd()String.prototype.trimStart()String.prototype.valueOf()String.prototype[@@iterator]()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |