JavaScript Objects The Strings Object- charCodeAt() - Javascript Objects

What is JavaScript String - charCodeAt() Method?

JavaScript String - charCodeAt() method returns a number representing the Unicode value of the character at the given index.

Unicode code points range from 0 to 1,114,111. The first 128 Unicode code points are a direct match of the ASCII character encoding. charCodeAt() always returns a value that is less than 65,536.

Syntax

Use the below syntax to find the character code at a particular index.

Argument Details

index − An integer between 0 and 1 less than the length of the string; if unspecified, defaults to 0.

Return Value

It returns a number representing the Unicode value of the character at the given index. It returns NaN if the given index is not between 0 and 1 less than the length of the string.

Example

Try the below example.

Output

str.charCodeAt(0) is:84

str.charCodeAt(1) is:104

str.charCodeAt(2) is:105

str.charCodeAt(3) is:115

str.charCodeAt(4) is:32

str.charCodeAt(5) is:105

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Javascript Objects Topics