JavaScript Character Set

Source: Internet
Author: User

JavaScript is case sensitive:

Keywords, variables, function names, and all identifiers must use the same case (generally we write them in lower case ), this is very different from C #'s simplified writing method.

For example: (Here we use the str and Str variables as examples)

Copy codeThe Code is as follows:
Var str = 'abc ';
Var Str = 'abc ';
Alert (str); // output abc

If str and Str are the same variables, then alert (str);, the output result should be ABC rather than abc, as shown in. This exactly shows that JavaScript is case sensitive.

Unicode escape sequence

The Unicode character set is used to make up for the limit that the ASCII code can only represent 128 characters. in daily life, if we want to display Chinese characters and Japanese characters, it is obviously impossible to use ASCII. Unicode is a superset of ASCII and Latin-1. First of all, JavaScript programs are written in the Unicode Character Set, but in some computer hardware and software, it is impossible to completely display or enter the full set of Unicode characters (such as: é ), to solve this problem, JavaScript defines a special sequence that uses six ASCII characters to represent any 16-bit Unicode Internal code. This special sequence is collectively called a Unicode escape sequence, it is prefixed with \ u, followed by 4 hexadecimal numbers

For example:

Copy codeThe Code is as follows:
Var str = 'caf \ u00e9 ';
Var Str = 'CA ';
Alert (Str + ''+ str); // you can see that the results are the same.
Alert (Str = str); // Output true

However, we should note that Unicode allows multiple methods to encode the same character. The preceding e-escape example is used to describe the following:

É:

1. Unicode Character \ u00E9 can be used for representation.

2. It can also be expressed by e \ u0301 (tone character)

Copy codeThe Code is as follows:
Var str = 'caf \ u00e9 ';
Var Str = 'cafe \ u0301 ';
Alert (str + ''+ Str); // As shown in, the output results of Str and str are the same.
Alert (Str = str); // The result is the same, but their binary encoding representation is different, so false is output.

Although the results displayed in the text editor are the same, their binary code representation is basically different, and the programming language will eventually convert to the computer mechanical code (Binary Code) of the local platform ), the computer can only know the result by comparing the binary encoding. Therefore, the final result for comparing them can only be false.

Therefore, this is the best explanation of "Unicode allows multiple methods to encode the same character, the Unicode Standard defines a preferred encoding format for all characters to facilitate the conversion of text into Unicode escape sequences in a unified format for appropriate comparison

Take é again as an example:

Is it the same to that in facé?

Both fac é and caf é can be converted to \ u00E9 or both can be converted to e \ u0301 to compare the files in fac é and caf é.

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.