On JavaScript Character Set _ Basics

Source: Internet
Author: User

JavaScript is case-sensitive:

Keywords, variables, function names, and all identifiers must be in a consistent case (we are usually written in lowercase), which is very different from the way we used to learn C # in many styles.

For example: (take variable str and str for example)

Copy Code code as follows:

var str= ' abc ';
var str= ' ABC ';
alert (str);//Output ABC

If STR is the same variable as STR, then alert (str), the result of the output should be ABC instead of ABC as shown above. This precisely explains that JavaScript is case-sensitive.

Unicode escape sequence

The Unicode character set appears to make up for the limitation that ASCII code can only represent 128 characters, while in everyday life we want to display Chinese characters and Japanese, it is obvious that ASCII is impossible. So Unicode is a superset of ASCII and Latin-1. First, JavaScript programs are written in the Unicode character set, but in some computer hardware and software can not fully display or enter the complete set of Unicode characters (such as: é), in order to solve this phenomenon JavaScript defines a special sequence, This sequence uses 6 ASCII characters to represent any 16-bit Unicode code, which is collectively known as a Unicode escape sequence, prefixed by \u, followed by 4 hexadecimal digits

Like what:

Copy Code code as follows:

var str= ' caf\u00e9 ';
var str= ' Café ';
Alert (str+ ' +str);//You can see that the display is the same effect.
alert (STR===STR);//Output True

However, we should note that Unicode is a way to allow multiple methods to encode the same character, as described in the above example of E-escape:

E:

1. You can use Unicode characters \u00e9 to represent

2. May also use e\u0301 (intonation character) to express

Copy Code code as follows:

var str= ' caf\u00e9 ';
var str= ' cafe\u0301 ';
Alert (str+ ' +str); As the following illustration shows, the results of STR and STR are the same
alert (STR===STR); The results are the same, but their binary encodings are different, so the output is false

Although the results displayed on the text editor are the same, but their binary coding is not the same, and the programming language will eventually be converted to the local computer machine code (binary code), the computer can only through the comparison of binary encoding to know the result, so they compare the final result can only be false

So that's why Unicode is the best explanation for allowing multiple methods to encode the same character, because the Unicode standard defines a preferred encoding format for all characters to facilitate the translation of text into a Unicode escape sequence in a uniform format for comparison

Take e again for example:

Compare Facé with café in the same?

Facé and Café in the e are converted to \U00E9 or all converted to e\u0301, in order to compare the Facé and café in the é

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.