Home » JavaScript

String fromCharCode() Method with Example in JavaScript

JavaScript String fromCharCode() Method: Here, we are going to learn about the fromCharCode() function in JavaScript with Example.
Submitted by IncludeHelp, on February 07, 2019

String fromCharCode() Method

fromCharCode() Method is a string method in JavaScript, it is used to get the character from the given Unicode(s). By using this function, we can get the characters from the given Unicode’s. Here, we can pass multiple numbers to get their corresponding characters.

Note: We can also provide the number in octal (following by 0) and hexadecimal format (following by 0x).

Syntax:

    String.fromCharCode(number1, number2, number2, ...);

It accepts one or more numbers (Unicode), and returns the characters of them.

Examples:

    Function call: 
    String.fromCharCode(65);
    Output:
    "A"

    Function call: 
    String.fromCharCode(65, 66);
    Output:
    "AB"

Code:

<html>
<head>
<title>JavaScipt Example</title>
</head>
<body>
<script>
	//passing values in decimal 
	document.write(String.fromCharCode(65) + "<br>");
	document.write(String.fromCharCode(65, 66) + "<br>");
	document.write(String.fromCharCode(65, 66, 67) + "<br>");
	document.write(String.fromCharCode(72, 69, 76, 76, 79) + "<br>");

	//passing values in octal
	document.write(String.fromCharCode(0101) + "<br>");
	document.write(String.fromCharCode(0101, 0102) + "<br>");
	document.write(String.fromCharCode(0101, 0102, 0103) + "<br>");
	document.write(String.fromCharCode(0110, 0105, 0114, 0114, 0117) + "<br>");	
	
	//passing values in hexadecimal 
	document.write(String.fromCharCode(0x41) + "<br>");
	document.write(String.fromCharCode(0x41, 0x42) + "<br>");
	document.write(String.fromCharCode(0x41, 0x42, 0x43) + "<br>");
	document.write(String.fromCharCode(0x48, 0x45, 0x4C, 0x4C, 0x4F) + "<br>");	
</script>
</body>
</html>

Output

A
AB
ABC
HELLO
A
AB
ABC
HELLO
A
AB
ABC
HELLO





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.
Learn PCB Designing: PCB DESIGNING TUTORIAL







Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.