Basic javascript syntax learning notes, javascript learning notes
I. Definition
Javascript is a scripting language (interpreted Programming Language) used to enhance the dynamic page effect and realize real-time and dynamic interaction between pages and users ). Javascript consists of three parts: ECMA, DOM, and BOM.
[1] ECMAScript is defined by ECMA-262 and provides core language functions (ECMA is the European Association of computer manufacturers)
[2] DOM Document Object Model, which provides interfaces for accessing and operating webpage content
[3] BOM browser object model, which provides interfaces for interacting with browsers
II. Introduction
There are two ways to introduce javascript: embedding js code in the page and introducing external files
[1] Page embedding
<script> alert("My First JavaScript");</script>
[2] introducing external js files
[Note] the <script> element with the src attribute should not include additional js Code between its <script> tag. If the embedded code is included, only the external scripts are downloaded and executed, while the embedded code is ignored.
<script src="myScript.js"></script>
<Script>
Either method requires the <script> label. <Script> tags share six attributes, of which the language attribute is obsolete.
[1] src: indicates the external file containing the code to be executed. This file can be cross-Origin
[2] charset: (optional) Character Set of the Code specified by the src attribute, which is ignored by most browsers.
[3] defer: (optional) indicates that the script can be executed after the file is completely parsed and displayed. It is only valid for external scripts.
[4] async: optional, indicating that the script should be downloaded immediately without interfering with other operations on the page. Valid only for external scripts
[5] type: (optional) It is an alternative property of language, indicating the content type of the script language used for coding, also known as the MIME type. Considering compatibility, it is generally text/javascript. If this parameter is not specified, the default value is text/javascript.
[6] language: obsolete
Async and defer
[1] If neither async nor defer is set, the browser will immediately load and execute the specified script
<Script src = "test. js"> </script>
[2] If only async is set, the browser downloads the script asynchronously without blocking other operations on the page.
[Note] the asynchronous script will be executed before the page load event.
<Script src = "test. js" async> </script>
[3] If only defer is set, the script will be delayed until the document is completely parsed and displayed before execution.
<Script src = "test. js" defer> </script>
Note
Annotations can improve code readability and help you read and understand Javascript code. The comments are not displayed on the webpage. They can be divided into single-line comments and multi-line comments.
// Single line comment/* multi-line comment */
Ignore Spaces
JavaScript ignores unnecessary spaces. You can add spaces to the script to improve readability.
// The following statements are correct: var name = "hello ";
Code line
You can use a backslash to wrap a line in a text string.
// The correct document. write ("Hello \ World! "); // Error document. write \ (" Hello World! ");
Case Sensitive
JavaScript variables, function names, and operators are case sensitive. The getElementById function differs from getElementbyID. Similarly, the variables myVariable and MyVariable are different.
Reserved Words and keywords
A ECMA-262 describes a set of keywords that have a specific purpose, used to indicate the beginning or end of a control statement, or to execute a specific action; the ECMA-262 also describes another set of reserved words that cannot be used as identifiers and they may become keywords in the future.
// Reserved word Class in non-strict mode of version 5th | enum | extends | super | const | export | import // reserved word Implements in strict mode of version 5th | package | public | interface | private | static | let * | protected | yield *
Articles you may be interested in:
- Summary of basic JavaScript syntax puzzles
- JavaScript advanced programming (version 3rd) Study Notes 2 Basic JavaScript syntax
- Basic Javascript knowledge (I) core basic syntax and event model
- Basic JavaScript syntax, dom operation tree, and document Object
- Basic Syntax of JavaScript learning notes
- Basic javaScript syntax
- Basic Syntax of JSP learning notes
- Sort basic Javascript syntax learning notes