[JavaScript] Stringa Code 관련

드한승훈·2020년 8월 26일
0

charCodeAt

UTF - 16 값을 반환한다.

const str = 'ABCD';

str.charCodeAt(0)//65
str.charCodeAt(1)//66
str.charCodeAt(2)//67
str.charCodeAt(3)//68
str.charCodeAt(4)//NaN

str.charCodeAt(index)

반환값

주어진 인덱스 대한 문자에 대한 UTF-16 코드를 나타내는 숫자

범위 밖으로 넘어갔을 경우 [NaN](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/NaN)

codePointAt

해당하는 Unicode 값을 반환한다.

const str = 'ABCD';

str.codePointAt(0)//65
str.codePointAt(1)//66
str.codePointAt(2)//67
str.codePointAt(3)//68
str.codePointAt(4)//undefined
const icons = '👍😎👃';

icons.codePointAt(5) //56387
icons.codePointAt(6) //undefined

str.codePointAt(index)

반환값

범위 밖으로 넘어갔을 경우 undefined

String.fromCharCode()

console.log(String.fromCharCode(189, 43, 190, 61));
// expected output: "½+¾="

String.fromCodePoint()

console.log(String.fromCodePoint(9731, 9733, 9842, 0x2F804));
// expected output: "☃★♲你"
profile
프론트 엔드 개발자

0개의 댓글