Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript

What is String.fromCharCode() in JS?

Hammad Nasir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The fromCharCode method is defined in the String class in JS and converts the given sequence of numbers to a string.

Syntax

String.fromCharCode(...);

Parameters

  • ... is a sequence of numbers (e.g., num1, num2, ..., numN) that specifies the UTF-16 encoding for the string.

Return value

  • A string of equivalent length to the number of arguments is returned. The string is constructed by treating the arguments as UTF-16 encoding units.

Example

console.log(String.fromCharCode(0x41, 0x42, 0x43));
console.log(String.fromCharCode(97, 98, 99));

In the example above, the first call to fromCharCode passed 3 arguments in hexadecimal notation that represent A, B, and C characters in UTF-16 encoding. The second call to fromCharCode passed 3 arguments as integers that represent a, b, and c characters in UTF-16 encoding.

RELATED TAGS

javascript

CONTRIBUTOR

Hammad Nasir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring