DEV Community

Sasireka
Sasireka

Posted on

ASCII Values of Each Character in JavaScript

What is ASCII?

ASCII (American Standard Code for Information Interchange) is a, standard code that assigns numerical values (0–127) to letters, numbers, and symbols, allowing computers to understand text.

It was the standard for character representation in computers and data communication from the 1960s, heavily influencing modern systems.

It primarily supports English; however, it serves as the base for Unicode (the first 128 Unicode characters are identical to ASCII).

Non-Printable Characters (0-31)

  • Example: 0 => Null , 8 => Backspace , 9 => Tab , 10 => New Line

Printable Characters (32-126)

  • Example: [65-90 => A-Z] , [97-122 => a-z] , [48-57 => 0-9(Numbers)]

Del Character (127)

  • Delete (Non-Printable)

Example Program:

let name = "silambu9391a@gmail.com";

for (let i = 0; i < name.length; i++) {
    console.log(name[i] + " = " + name.charCodeAt(i));
}
Enter fullscreen mode Exit fullscreen mode

Explanation:

  • i = 0 → starts from first character

  • name.length → total number of characters

  • i++ → moves to next character

  • Gets character at position i

Example:
name[0] → 's'
name[1] → 'i'
name[2] → 'l'

  • name.charCodeAt(i)

  • Converts character → ASCII number

Example:
's' → 115
'i' → 105
'l' → 108
'a' → 97

  • Prints: character = ASCII value

Output:

Top comments (0)