Related free learning recommendations: JavaScript (Video)
If you already know how to write html and css, but you haven't learned JavaScript yet, you can start learning from the author's article here.
can be written in three places in total.
<button onclick='alert("hello")'>按钮</button>
<script type="text/javascript"> //type="text/javascript"可忽略 //你的JS代码</script>
<script src="./index.js"></script>
Note Points:
1. src introduces the external JS file path
2. must appear alone
3. Between the start and end tags. No JS code will appear, and it will not be executed if it appears.
Output:
Input:
Variable: Data storage space in memory. The data stored in this space can change as the operation proceeds.
Three elements of variables:
1. Variable name
2. Variable value
3. Data type
JS is a weak (dynamic) type language and does not care about variables The data type at creation time can only be determined after running.
Syntax:
Define variables:
var 变量名 = 变量值;//分解var 变量名;变量名 = 变量值;
In actual project development process, var is basically not used to declare variables. Generally, const and let are used to declare variables, because var has problems with reputation enhancement and memory leaks. For information on const and let, please see author b’s introduction to ES6.
Naming rules for variables:
a. Characters that can be included: letters, numbers, _, $
b. It cannot start with a number
c. It cannot be a keyword or Reserved words
Keywords/reserved words: Words with fixed grammatical meaning
For details on keywords and reserved words, please go to ECMAScript keywords and reserved words for detailed introduction
d. Strictly distinguish between uppercase and lowercase letters
Naming specifications for variables:
a. Use concise English words as variable names, so that the meaning can be understood by the name.
b. When there are multiple words, the first letter of the first word is lowercase, and the first letter of other words is capitalized.
If you already know how to write html and css, but you haven’t learned JavaScript yet, you can start learning from the author’s article here.
can be written in three places in total.
<button onclick='alert("hello")'>按钮</button>
<script type="text/javascript"> //type="text/javascript"可忽略 //你的JS代码</script>
<script src="./index.js"></script>
Note Points:
1. src introduces the external JS file path
2. must appear alone
3. Between the start and end tags. No JS code will appear, and it will not be executed if it appears.
Output:
Input:
Variable: Data storage space in memory. The data stored in this space can change as the operation proceeds.
Three elements of variables:
1. Variable name
2. Variable value
3. Data type
JS is a weak (dynamic) type language and does not care about variables The data type at creation time can only be determined after running.
Syntax:
Define variables:
var 变量名 = 变量值;//分解var 变量名;变量名 = 变量值;
In actual project development process, var is basically not used to declare variables. Generally, const and let are used to declare variables, because var has problems with reputation enhancement and memory leaks. For information on const and let, please see author b’s introduction to ES6.
Naming rules for variables:
a. Characters that can be included: letters, numbers, _, $
b. It cannot start with a number
c. It cannot be a keyword or Reserved words
Keywords/reserved words: Words with fixed grammatical meaning
For details on keywords and reserved words, please go to ECMAScript keywords and reserved words for detailed introduction
d. Strictly distinguish between uppercase and lowercase letters
Naming specifications for variables:
a. Use concise English words as variable names, so that the meaning can be understood by the name.
b. When there are multiple words, the first letter of the first word is lowercase, and the first letter of other words is capitalized.
The above is the detailed content of Learn how to write JavaScript. For more information, please follow other related articles on the PHP Chinese website!