Basic Syntax of JavaScript learning notes and javascript learning notes

Source: Internet
Author: User
Tags try catch

Basic Syntax of JavaScript learning notes and javascript learning notes

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.

Copy codeThe 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: with (<Object>) {<statement group>}

That is:

Copy codeThe 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:

Copy codeThe 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.

Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Title> withTest.html </title>
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "description" content = "this is my page">
<Meta http-equiv = "content-type" content = "text/html; charset = UTF-8">
<! -- <Link rel = "stylesheet" type = "text/css" href = "./styles.css"> -->
</Head>
<Body>
<Script type = "text/javascript">
With (document ){
Write ("Hello! ");
Write ("<br> the title of this document is \" "+ title + "\".");
Write ("<br> the URL of this document is:" + URL );
Write ("<br> you do not need to write the document Object prefix every time! ");
}
</Script>
</Body>
</Html>

4. Disconnected rows

You can use a backslash to disconnect a code:

Copy codeThe Code is as follows:
Document. write ("Hello \
World! ");

But it cannot be broken:

Document. write \
("Hello World! ");

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.