JavaScript Basic Grammar Learning notes _javascript tips

Source: Internet
Author: User
Tags comments object model reserved

I. Definition
JavaScript is a scripting language (interpreted programming language) that enhances the dynamic effect of pages and enables real-time, dynamic interaction between pages and users. JavaScript is made up of three parts: ECMA, Dom, and BOM

[1] ECMAScript is defined by ECMA-262 and provides core language features (ECMA is the European Computer Manufacturers Association)

[2] DOM Document Object model, an interface that provides methods to access and manipulate Web page content

[3] BOM Browser object model, an interface that provides methods for interacting with browsers

Second, introduce
There are two ways to introduce javascript: embed the JS code inside the page and introduce the external file

[1] Embedded inside the page

<script>
  alert ("My I-JavaScript");
</script>

[2] Introduction of external JS files

[note] The <script> element with the SRC attribute should not contain additional JS code between its <script> tags, and if the embedded code is included, only the external script is downloaded and executed, and the embedded code is ignored

<script src= "Myscript.js" ></script>

<script>

Whichever approach you introduce, you need to use the <script> tag. <script> tags share 6 properties, where the language property has been discarded

[1]SRC: Represents an external file that contains the code to execute, which can cross domain

[2]charset: Optional, representing the character set of the code specified through the SRC attribute, most browsers ignore

[3]defer: optional, which means that the script can be deferred until the document is completely parsed and displayed and then executed only for external scripts

[4]async: optional, which means that the script should be downloaded immediately, without interfering with other actions of the page. Valid only for external scripts

[5]type: Optional, is an alternate attribute of language that represents the content type, also known as the MIME type, of the scripting language used by the code. Considering the compatibility, generally or text/javascript, if not specified, the default value is also Text/javascript

[6]language: Obsolete

Async and Defer

[1] If both async and defer are not set, the browser loads and executes the specified script immediately

<script src= "Test.js" ></script>
[2] If only async is set, the browser downloads the script asynchronously and does not block other actions on the page

[note] The asynchronous script must be executed before the page's Load event

<script src= "Test.js" async></script>
[3] If only the defer is set, the script is deferred until the document is completely parsed and displayed before execution

<script src= "Test.js" defer></script>

Comments
Annotations can improve the readability of your code, help yourself and others read and understand JavaScript code, and the contents of comments are not displayed in the Web page, and are divided into single-line and multiline comments

Single-line Comment
*/
Multiline Comment
 * *

Ignore spaces
JavaScript ignores extra spaces and can add spaces to the script to improve its readability

The following wording is correct
var name= "Hello";
var name = "Hello";
var name = "Hello";

Code Folding Lines
You can use backslashes to wrap lines of code in a text string

Correct
document.write ("Hello \
world!");
Error
document.write \

Case sensitive
JavaScript variables, function names, and operators are case-sensitive. The function getElementById differs from the getElementById, and the variable myvariable and myvariable are also different

Reserved words and keywords
ECMA-262 Describes a set of keywords that are used to indicate the start or end of a control statement, or to perform a particular operation, and ECMA-262 also describe another set of reserved words that cannot be used as identifiers, and they may become keywords in the future.

5th edition reserved word Class in non-strict mode
| enum | extends | super | const | export | Import 
//5th edition in strict mode reserved word
Implements | package | Public | interface | Private | static | let* | protected | yield*

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.