Home > Web Front-end > JS Tutorial > Basic syntax of JavaScript learning notes

Basic syntax of JavaScript learning notes

韦小宝
Release: 2017-11-30 09:43:37
Original
1511 people have browsed it

JavaScript Learn the basic grammar of notes. For students who are not familiar with JavaScript and are not familiar with the basic grammar of JavaScript, you can save it and take a look!

Various arithmetic operators, comparison operators,logical operators;

if else statement,switch statement;

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

The following contents are all different parts of JavaScript.

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

1. Congruence judgment

There is a congruence judgment === in JavaScript comparison operator, which is used to judge whether the value and type are both 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

Traverse the properties of the object.

var person={fname:"John",lname:"Doe",age:25};
for (x in person)
{
      txt=txt + person[x];
}
Copy after login
Where x is the attribute name, person[x] is the value of the attribute.
3.With statement

With the With statement, when accessing the objectproperties and methods There is no need to repeatedly specify the reference object. In the With statement block, all properties and methods that are not recognized by JavaScript are related to the object specified by the statement block.
Function: Create a default object for a program.

Format: with (){ } That is:

      With Object {
      Statements
      }
Copy after login

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

      document.writeln(”Hello!“);
Copy after login

If a large amount of data needs to be displayed, the same document.writeln() statement will be used multiple times. In this case, it can be like the following program , put all the statements with the Document object as the reference object into the With statement block, thereby reducing the number of statements.

<!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("您好 !");
            write("<br>这个文档的标题是 : \"" + title + "\".");
            write("<br>这个文档的 URL 是: " + URL);
            write("<br>现在不用每次都写出 document对象的前缀了!");
        }
    </script>
</body>
</html>
Copy after login

4. Line break

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

document.write("Hello \
World!");
Copy after login
But you can’t break the sentence like this:
document.write \("Hello World!");
Copy after login

The above is the content of the basic grammar of JavaScript learning notes. I hope it will be helpful to students. For more information, please search on this site!

Related recommendations:

javascript programming essentials_JS grammar dictionary_basic knowledge

Summarize 10 common methods in js syntax to improve coding efficiency

Manipulate JSON objects in Javascript and add simple implementations of deletion and modification

The above is the detailed content of Basic syntax of JavaScript learning notes. For more information, please follow other related articles on the PHP Chinese website!

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