2.1 How to introduce JS file
(1) Introduction of external JS
Example:
(2) on the current page
Example:
This part of the content can be placed anywhere on the page. But it is usually placed at the bottom of the page. This makes it easy for the page to load and then execute the JS file.
2.2 Syntax
Grammar: The rules of language structure.
Statement: The instruction is the basic unit that makes up any script.
Recommendation: Add a semicolon at the end of each statement.
Note: single-line Comment "//", multiline Comment "/*....*/" (HTML-style comments are not recommended in JS code)
Variable
Variable declaration:
< Script > var Mood;//mood, "Mood" var Age ; </ Script >
Other ways (Assignment method):
<Script> //First Kind varMood="Happy"; var Age= -; //The second Kind varmood2="Sad", Age2= at; //Third Kind varMood3,age3; Mood3="Cool"; Age3= -; //where the second most efficient, a statement is equivalent to the sum of the third method</Script>
Some naming conventions:
In the JavaScript language, the names of variables and other grammatical elements are case-sensitive.
JavaScript syntax does not allow a variable name to contain spaces or punctuation (the dollar sign "$" exception)
JavaScript variable names are allowed to contain letters, numbers, dollar signs, and underscores (but the first character is not allowed to be a number)
Hump format naming:
Remove Middle white space (underline), followed by each new word start with uppercase letters
< Script > var ="happy"; </ Script >
Usually the hump format is the preferred format for function name, method name, and object property name naming
Simple "Happy" is a literal (literal) in the JavaScript language, which is data that can be written directly in JavaScript code.
"Var" is a keyword, mymood is a variable name.
Cond...
JavaScript DOM Programming Art (2nd edition)---P9