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

Basic syntax of JavaScript learning notes

韦小宝
韦小宝Original
2017-11-30 09:43:371478browse

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];
}
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 (a87fdacec66f0909fc0757c19f2d2b1d){ 9f6ace05b7549af30d346c7bb6f534fe } That is:

      With Object {
      Statements
      }

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

      document.writeln(”Hello!“);

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>

4. Line break

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

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

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!

Statement:
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