Javascriptdhtml basic knowledge page 1/2

Source: Internet
Author: User

The following tutorials are for the JScript you mentioned above. based on the knowledge of CHM, if you have not read JScript. CHM. We recommend that you download it first, read the manual, and read the tutorial.

The syntax of JS is similar to that of most C-like languages. The difference lies only in its own features. So I will not write more details about the syntax. I should read more about the manual.

Five major JS objects: String, number, Boolean, object, and function.

JS four loops:
For (VAR I = 0; I <n; I ++ ){}
Do {} while (true );
While (true ){}
For (var I in Collection ){}

Exception Handling:
Try {} catch (avariable ){}

I will not list the JS syntax one by one. Here, I will explain only a few JS objects, but I may not have mentioned this in the manual.

1. String.
Strings are the most commonly used. There are at least two ways to forcibly convert a string:
1. Use the string connector "+. + In JS, if it is an operation, it is a plus. If it is a string, it is concatenated. For example:
<SCRIPT>
VaR a_number = 1000
VaR a_string = a_number + "";
</SCRIPT>

2. Use string to force transformation (string ).
<SCRIPT>
VaR a_number = 1000
VaR a_string = string (a_number );
</SCRIPT>
Note that the above is about forced transformation, and there is no "new" keyword before the string. If the new keyword is added, a string object is obtained. Objects can contain attributes and methods, but strings cannot. You can make a comparison as follows:
<SCRIPT>
VaR a_number = 1000
VaR a_string = string (a_number );
A_string.property = "JS ";
Alert (a_string.property) // will prompt undefined

VaR a_object = new string (a_number)
A_object.property = "JS ";
Alert (a_object.property) // JS will be prompted
</SCRIPT>
Therefore, there is a difference between new and new. This is true in number and Boolean, so we will not talk about this transformation in the future.

2. Number ).
Here we also talk about the transformation issue.
In addition to using number for forced transformation, you can also use parseint and parsefloat to convert to an integer or floating point type. If it is not a number after the transformation, Nan (not a number) will be returned. At this time, you can use the isnan function to judge. Here you can check the manual to see the syntax in it. Remember this function by the way.

3. boolean ).
This one is a little more troublesome, because JS processes it strangely.
In addition to the JScript manual,
An expression with a value of true or false. If needed, non-boolean expressions can also be converted to boolean values, but follow the following rules:

All objects are treated as true.
If and only if the string is null, the string is treated as false.
Null and undefined are treated as false.
If and only when the number is zero, the number is treated as false.
Note:

First, when it is neither true nor false before it is forcibly converted to a Boolean Type
1. In the numerical condition judgment, there are generally three situations: 0, negative, positive, as long as the value is not 0, it is true. The following is an example.
<SCRIPT>
VaR a = 0;
VaR B =-1;
VaR c = 1;

Function assert (Avar ){
If (Avar) Alert (true );
Else alert (false );
}
Assert (a) // false
Assert (B) // true
Assert (c) // true
</SCRIPT>
Note: In the preceding example, The Condition Statement is directly judged. If we change the condition statement:
<SCRIPT>
VaR a = 0;
VaR B =-1;
VaR c = 1;

Function assert (Avar ){
If (Avar = true) Alert (true );
Else alert (false );
}
Assert (a) // false
Assert (B) // false
Assert (c) // true
</SCRIPT>
Negative numbers have different results.

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.