JavaScript Basic Grammar explanation

Source: Internet
Author: User
Tags comments html comment html tags

This article mainly introduces the basic grammar of JavaScript, including annotation and writing format, such as basic knowledge, need friends can refer to the following

JavaScript consists of HTML tags placed in the JavaScript statement in the Web page.

can add

The script label has two important attributes:

Language: Used by the scripting language specified by this property. Typically, its value is JavaScript. Although the most recent version of HTML (and XHTML, its successor) is no longer using this property.

Type: This property is now recommended to indicate that the scripting language used and its value should be set to "Text/javascript".

So, your JavaScript fragment should be like this:

?

1 2 3 <script language= "javascript" type= "Text/javascript" > JavaScript code </script>

First JavaScript script:

Let's write an example to print out "Hello world".

?

1 2 3 4 5 6 7 8 9

JavaScript code optional HTML annotation. This is where the code does not support JavaScript browsers. End with "//->" annotation. "//" represents a comment in JavaScript, so we added to prevent the browser from reading the end of the HTML comment as a section of JavaScript code.

Next, we call a function document.write its write string to the HTML document. This function can be used to write text, HTML, or both. So the code above shows the following results:

?

1 Hello world!

Spaces and Line wrapping:

JavaScript ignores spaces, tabs, and line breaks appear in JavaScript programs.

Because then you are free to format and indent programs in a neat, consistent way that makes code easy to read and understand, you can use spaces, tabs, line breaks and free in your program.

Semicolons are optional:

Generally followed by a semicolon in JavaScript in simple statements, just because they are in c,c++ and Java. JavaScript, but you can ignore this semicolon if each statement is placed on a separate line. For example, the following code can be written without using a semicolon

?

1 2 3 4 5 6 <script language= "javascript" type= "Text/javascript" > <!--var1 = ten var2 =//--> </script>

However, a semicolon is required when a line is formatted as follows:

?

1 2 3 4 5 <script language= "javascript" type= "Text/javascript" > <!--var1 = 10; VAR2 = 20; --> </script>

Note: Using semicolons is a good programming practice.

Case sensitive:

JavaScript is a case-sensitive language. This means that the language's keywords, variables, function names, and any other identifiers must always be written in the same case with a single letter.

So identifier time, time, and time have different meanings in JavaScript.

Note: The variables and function names should be noted in JavaScript.

Notes in javascript:

JavaScript supports C-style and C + +-style annotations, so:

And the end of the line all text will be treated as a comment that will be ignored by JavaScript.

The character of any text between/* and * * is treated as a comment. This may span multiple lines.

JavaScript also admits that HTML annotations are open in an unrecognized order , so JavaScript should be written as//-->.

Example:

?

1 2 3 4 5 6 7 8 9 10 11 <script language= "javascript" type= "Text/javascript" > <!--/This is a comment. It is similar into comments in C + + * * This is a multiline comment in JavaScript * It's very similar to comments in C Pr ogramming * *//--> </script>
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.