Home > Web Front-end > JS Tutorial > body text

Basic syntax of JavaScript study notes_Basic knowledge

WBOY
Release: 2016-05-16 16:18:39
Original
1019 people have browsed it

Many basic contents in JavaScript are basically the same as those in Java, so there is no need to repeat them separately, including:

Various arithmetic operators, comparison operators, logical operators;

 if else statement, switch statement;

for loop, while loop, do while loop;

Tag, break, continue;

 try catch throw statement.

You can check the reference links at the end of the article.

The content that follows are all different parts of JavaScript.

This article will first talk about the differences in several details in the above content.

1. Congruent judgment
There is an equality judgment === in the comparison operator of JavaScript, which is used to judge 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 properties of an object.

Copy code The code is as follows:

var person={fname:"John",lname:"Doe",age:25};
for (x in person)
{
txt=txt person[x];
}

Where x is the attribute name and person[x] is the value of the attribute.

3.With statement

With the With statement, there is no need to repeatedly specify the reference object when accessing object properties and methods. In the With statement block, all properties and methods that are not recognized by JavaScript are related to the object specified in the statement block.

Function: Create a default object for a program.

Format: with (){ }

That is:

Copy code The code is as follows:

With Object {
Statements
}

Example: When using the write() or writeln() method related to the Document object, the following form is often used:

Copy code The code is as follows:

Document.writeln("Hello!");

If you need to display a large amount of data, you will use the same document.writeln() statement multiple times. In this case, you can put all the statements with the Document object as the reference object into the With statement block like the following program. , thereby achieving the purpose of reducing the number of statements.

Copy code The code is as follows:




withTest.html









4. Line break

You can use a backslash to break a line of code:

Copy code The code is as follows:

document.write("Hello
World!");

But you can’t break the sentence like this:

document.write
("Hello World!");

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template