본문 바로가기

Javascript

JavaScript 자바스크립트 String.fromCodePoint() 사용법 예제 String.fromCharCode 차이

반응형

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));

 

 

 

반응형