Javascript language structure note (1)

Source: Internet
Author: User

I. js supports Unicode character sets, so you can use Chinese naming functions.

Ii. js does not have initialization variables in Var. The default value is undefined.

III. For variables that are neither declared nor assigned values, if directly used, a system-level Error will be thrown. If typeof (typeof is a type operator) is used, whether it is declared or not, an undefined string is returned ";

Example:

// A is not declared

Alert (typeof (a); // undefined

Alert (a); // Error

4. Arithmetic Operators. "+" Can be used to easily convert a value into a string. The specific operation is to add this value to an empty string (or not to write ).

Example:

Var a = 2.96;

Var B = 1.0;

Alert (a + "+ B); // obtain the string" 2.961"

You can use "-" to replace a string with a value. The specific operation is to subtract a value 0 from the string.

Var a = "2.96 ";

Alert (a + 1); // obtain the string "2.961" (forcibly convert the value to a string)

Alert (a-0 + 1); // get the value 3.96

Here is an example I made:
Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>
<Title> js </title>
<Script language = "javascript">
X = 5 + 5;
Document. write (x + "<br> ");
X = "5" + "1 ";
Document. write (x + "<br> ");
X = "5" + 5;
Document. write (x + "<br> ");
X = "10"-5;
Document. write (x + "<br> ");
</Script>
</Head>
<Body>
</Body>
</Html>

Result:

10
51
55
5

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.