JavaScript ASCII Value

We will understand the JavaScript ASCII Value in this article.

ASCII

It stands for the American Standard Code for Information Interchange. It is a character encoding format utilized to communicate between computers. It provides standard numeric values to numerals, letters, etc.

There are 128 unique characters in ASCII. It contains both lowercase and uppercase letters from A to Z, numeral from 0 to 9, punctuation symbols and other characters.

We will understand how to find the ASCII value of a character in JavaScript. There are various methods to find the ASCII value of a character.

  • Utilizing charCodeAt()
  • Utilizing codePointAt()
  • Utilizing Array.from() method with charCodeAt()
  • Utilizing Array.from() method with codePointAt()
  • Utilizing the charCodeAt(index) method

We will understand all methods to find the ASCII value of a character one by one.

Utilizing the charCodeAt()

The charCodeAt() function is utilized to take the index value as input and returns the integer value which signifies its UTF-16 code i.e., number between 0 and 65535. The default index value for charCodeAt() is 0.

Demonstration:

We will utilize the charCodeAt() method in this demonstration to find the ASCII value of a character.

Code:

Output:

The outcome demonstrates the ASCII value of the character "n" which is discovered by utilizing the charCodeAt() method.

JavaScript ASCII Value

Utilizing the codePointAt()

The codePointAt() function is utilized to get the ASCII value of a character. It takes the three-character string as input and returns the value of code point. The default index value for codePointAt() is 0.

Demonstration:

We will utilize the codePointAt() method to acquire the ASCII value of a character.

Code:

Output:

Here in the outcome given downwards we can witness the ASCII value of a character "@" which is found with the help of codePointAt() method.

JavaScript ASCII Value

Utilizing Array.from() method with charCodeAt()

We will obtain the ASCII value of a full string with the utilization of the Array.from() function with the charCodeAt().

Demonstration:

We will discover the ASCII value of a character utilizing the Array.from() method with the charCodeAt() method. The Array.from() method alters the string into an array and then each array is transformed into the ASCII value.

Code:

Output:

We can gaze at the outcome which demonstrates the ASCII value of the full string "Welcome" which is discovered utilizing Array.from() method with the charCodeAt() method.

JavaScript ASCII Value

Utilizing Array.from() method with the codePointAt()

We will obtain the ASCII value of a full string by the utilization of the Array.from() function with the codePointAt().

Demonstration:

We will utilize the Array.from() method with the codePointAt() function in this illustration to achieve the ASCII value of a character. The Array.from() function is utilized to alter the string into an array and then each array is converted into the ASCII value.

Code:

Output:

Here in the output downwards we can clearly witness the ASCII value of the full string "Hello" which is achieved by utilizing the Array.from() method with the codePointAt() method.

JavaScript ASCII Value

Utilizing the charCodeAt(index) method

We can find the ASCII value of a particular index by utilizing the charCodeAt(index).

Demonstration:

We will make the utilization of the charCodeAt(index) method in this demonstration to acquire the ASCII value of a character at a particular index.

Code:

Output:

We can clearly witness the ASCII value of a character at index 10.

JavaScript ASCII Value

Conclusion:

We have comprehended the JavaScript ASCII value in this article. The ASCII is short for the American Standard Code for Information Interchange which is utilized to communicate between devices. We have learned how to find the ASCII value of a character utilizing charCodeAt() method, codePointAt() method, Array.from() method with charCodeAt(), Array.from() method with codePointAt() and charCodeAt(index) method.






Latest Courses