About ASCII and Unicode

ASCII and Unicode are two different standards for representing text and characters on computers and other devices. ASCII was developed first, and it only includes a limited number of characters, mostly the ones you would find on a standard English keyboard. Unicode, on the other hand, includes many more characters and symbols, including letters and symbols from many different languages.

ASCII is a simpler and older standard, and it only uses one byte (8 bits) to represent each character. This means that it can only represent up to 256 different characters. Unicode, on the other hand, uses more than one byte to represent each character, so it can represent many more characters, including emojis 😊.

Today Unicode is a more widely used standard, as it allows us to use a wider range of characters and symbols in our text.

JavaScript

In JavaScript, you can convert a Unicode character to a number by using the charCodeAt() method of the String object. This method returns the Unicode code point of the character at the specified index.

Here's an example of how you can use the charCodeAt() method to convert a Unicode character to a number:

let str = 'Hello, world!';
let code = str.charCodeAt(0);
println(code);  // Output: 72

In this example, we first define a string 'Hello, world!'. Then, we use the charCodeAt() method to get the Unicode code point of the first character in the string (which is the letter 'H'). Finally, we print the code on the screen, and the output is 72, which is the Unicode code point for the letter 'H'.

You can also use the fromCharCode() method of the String object to convert a Unicode code point to a character. Here's an example of how you can use this method:

let code = 72;
let char = String.fromCharCode(code);
println(char);  // Output: H

In this example, we first define a variable code with the value 72, which is the Unicode code point for the letter 'H'. Then, we use the fromCharCode() method to convert this code point to the corresponding character, and store the result in the char variable. Finally, we print the character, and the output is H.

Next steps

Please see also the article about ASCII and also explore the varios text based projects here on codeguppy.com

Read more blog articles Browse JavaScript projects

About codeguppy

CodeGuppy is a FREE coding platform for schools and intependent learners. If you don't have yet an account with codeguppy.com, you can start by visiting the registration page and sign-up for a free account. Registered users can access tons of fun projects!


Follow @codeguppy on Twitter for coding tips and news about codeguppy platform. For more information, please feel free to contact us.