Basic Syntax of JavaScript learning notes _ basic knowledge-js tutorial

Source: Internet
Author: User
This article is not a zero-based teaching. If you have no javascript basics, turn left first. I learned java before, so this article mainly compares java to learn javascript. Many basic content in JavaScript is basically the same as that in Java, so you do not need to repeat it separately, including:

Various Arithmetic Operators, comparison operators, and logical operators;

If else statement and switch statement;

For Loop, while loop, do while loop;

Tags, break, and continue;

Try catch throw statement.

You can view the Reference Links after the document.

The subsequent content is different parts of JavaScript.

In this article, we will talk about several details in the above section.

1. Full equality judgment
The comparison operator of JavaScript has a full equality ===, which is used to determine whether the values and types are equal.

2. for/in Loop
The for/in loop in JavaScript is a bit like the enhanced for loop in Java, but it is used to traverse the attributes of objects.

The Code is as follows:


Var person = {fname: "John", lname: "Doe", age: 25 };
For (x in person)
{
Txt = txt + person [x];
}

Here, x is the property name, and person [x] is the value of this property.

3. With statement

With the With statement, you do not need to specify the reference object again when accessing the object attributes and methods. In the With statement block, any properties and methods that JavaScript does not recognize are related to the objects specified by the statement block.

Function: Creates a default object for a program.

Format: ( <对象> ){ <语句组> }

That is:

The Code is as follows:


With Object {
Statements
}

For example, when using the write () or writeln () method related to the Document object, the following format is often used:

The Code is as follows:


Document. writeln ("Hello! ");

If you need to display a large amount of data, the same document will be used multiple times. writeln () statement. In this case, all the statements With Document objects as reference objects can be placed in the With statement block as the program below to reduce the number of statements.

The Code is as follows:





WithTest.html






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.