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.
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:
Example: When using the write() or writeln() method related to the Document object, the following form is often used:
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.
4. Line break
You can use a backslash to break a line of code:
But you can’t break the sentence like this:
document.write
("Hello World!");