ASCII Codes in Javascript 🔥

Опубликовано: 08 Март 2024
на канале: RoadsideCoder
7,391
441

In JavaScript, you can work with ASCII codes using the charCodeAt() method to get the ASCII value of a character and String.fromCharCode() method to convert an ASCII value to a character.

Here's how you can use these methods:

// Get the ASCII value of a character
const char = 'A';
const asciiValue = char.charCodeAt(0);
console.log('ASCII value of', char, 'is', asciiValue);

// Convert an ASCII value to a character
const asciiCode = 65;
const character = String.fromCharCode(asciiCode);
console.log('Character for ASCII code', asciiCode, 'is', character);

This will output:

ASCII value of A is 65
Character for ASCII code 65 is A