반응형
JavaScript
String.fromCodePoint()
String.fromCodePoint()
- Code points의 순서에 따라 해당 번호의 문자를 반환
기본 구문
String.fromCodePoint(num1, num2, ,,,)
매개 변수
-
반환 값
code points에 해당하는 문자 반환
String.fromCodepoint() vs String.fromCharCode()
(예제2 참고)
String.fromCodePoint(), on the other hand, can return 4-byte supplementary characters, as well as the more common 2-byte BMP characters, by specifying their code point (which is equivalent to the UTF-32 code unit):
String.fromCharCode() cannot return supplementary characters (i.e. code points 0x010000 – 0x10FFFF) by specifying their code point. Instead, it requires the UTF-16 surrogate pair in order to return a supplementary character:
예제1
& String.fromCharCode() 와의 차이
console.log('-------String.fromCodePoint--------')
// fromCodePoint()
console.log(String.fromCodePoint(1,3,5,2,1));
console.log(String.fromCodePoint(1234));
console.log(String.fromCodePoint(2345));
console.log(String.fromCodePoint(9731,9733,9842,0x2f804));
console.log('-------String.fromCharCode--------')
// fromCharCode()
console.log(String.fromCharCode(1,3,5,2,1));
console.log(String.fromCharCode(1234));
console.log(String.fromCharCode(2345));
console.log(String.fromCharCode(9731,9733,9842,0x2f804));
예제2
console.log(String.fromCharCode(0xD83C,0xDF03));
console.log(String.fromCharCode(55356,57091));
console.log(String.fromCodePoint(0x1F303));
반응형
'Javascript' 카테고리의 다른 글
[JavaScript] Switch ...case 조건문과 if ...else 차이는? 예제로 알아보기 자바스크립트 switch문 (1) | 2021.05.24 |
---|---|
JavaScript 자바스크립트 String.fromCharCode() 사용법 , 예제 String.fromCodePoint와 차이점 (0) | 2021.05.23 |
JavaScript 자바스크립트 .reduce() 사용법, 연습 예제 (0) | 2021.05.21 |
JavaScript 자바스크립트 .concat() 사용법, 연습 예제 (0) | 2021.05.21 |
JavaScript 자바스크립트 재귀함수 (0) | 2021.05.21 |