Home  >  Article  >  Web Front-end  >  What character function does javascript use to convert ascii to characters

What character function does javascript use to convert ascii to characters

青灯夜游
青灯夜游Original
2021-10-13 16:31:315571browse

In javascript, you can use the fromCharCode() function of the String object to convert the ascii code into the corresponding character. This function can accept a specified Unicode value and then return a string; the specific syntax is "String.fromCharCode (ascii code)".

What character function does javascript use to convert ascii to characters

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In javascript, you can use the fromCharCode() function of the String object to convert the ascii code into the corresponding character.

Example:

var num = 97;
console.log(String.fromCharCode(num));  // 'a'

var num1 = 100;
console.log(String.fromCharCode(num1));  // 'd'

Output result:

What character function does javascript use to convert ascii to characters

Description:

fromCharCode() accepts one The specified Unicode value, then returns a string.

Note: This method is a static method of String. Each character in the string is specified by a separate Unicode numeric encoding.

Syntax: String.fromCharCode(n1, n2, ..., nX)

Return value: Returns the character representing Unicode encoding.

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of What character function does javascript use to convert ascii to characters. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn