JavaScript language Structure small note (i) _ Basic knowledge

Source: Internet
Author: User
Tags arithmetic operators character set numeric value
One: JS supports the Unicode character set, so you can use the Chinese name function.

Two: JS in Var has not initialized the variable, the default is undefined

Third: For variables that are not declared and unassigned, if used directly, a system-level error is thrown, and if TypeOf (TypeOf is a type operator), the string "undefined" is returned, whether or not it has been declared;

Cases:

A not stated

Alert (typeof (a));//undefined

alert (a);//error

IV: Arithmetic operators. With "+" you can easily convert a number to a string, the action is the operation is to add this value to an empty string (also can not write).

Cases:

Var a=2.96;

Var b=1.0;

Alert (+ "" +b);//Get String "2.961"

Use "-" to replace a string with a numeric value by subtracting the string by a value of 0

Var a= "2.96";

alert (a+1);//Get String "2.961" (cast numeric value to string)

alert (a-0+1);/Get a value of 3.96

Here's a example I do:
Copy Code code as follows:

<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>
<body>
</body>

Results:

10
51
55
5
Related Article

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.