JavaScript String fromCharCode()

Last Updated On Saturday 9th Apr 2022

The JavaScript String fromCharCode() method returns a string created from the specified sequence of UTF-16 code units.

Syntax

	String.fromCharCode(num1)
String.fromCharCode(num1, num2)
String.fromCharCode(num1, num2, ..., numN)
	

Parameters

  • A sequence of numbers.The range is between 0 and 65535 (0xFFFF).
  • Numbers greater than 0xFFFF (65535) are truncated.

Return value

  • Returns a string of length N consisting of the N specified UTF-16 code units.

Note: The fromCharCode() method returns a string and not a String object.

Example : Using fromCharCode() method

	const str1 = String.fromCharCode(67, 74);
console.log(str1); // CJ

// num > 65535 are truncated, so here 1 is 
const str2 = String.fromCharCode(0x12014);
console.log(str2); // —

const str3 = String.fromCharCode(64);
console.log(str3); // @

const str4 = String.fromCharCode(100);
console.log(str4); // d

const str5 = String.fromCharCode(600);
console.log(str5); // ɘ

const str6 = String.fromCharCode(0xD83E, 0xDD26);
console.log(str6); // 🤦
	

Output

	CJ
—
@
d
ɘ
🤦
	

Which method is used for convert numbers to equal ASCII characters ?