Javascript主要分为ECMAScript + DOM + BOD
ECMAScript2015(ES5)
Preface
输出语句
- console.log() is actually the method under window.console.log() window object
- alert() is actually the method under window.alert() window object
REPL环境
- Read
- Eval execution
- Loop
前端三层
- Structural layer
- Style layer
- Behavioral layer
*variable
定义变量
The var keyword defines a variable or defines multiple variables at the same time, separated by ','
When
the variable defined by var a is not assigned an initial value, the default value is undefined
have b = 13
关键字 变量 赋值运算符 值
var c = 13, d = 15
define multiple variables at the same time
变量的提升
- Only promote the variable name, not the value
- Before executing all the code, JS has a pre-analysis stage, which will pre-read the definition of all variables. This is the reason why variables can be improved.
变量的使用
console.log(a)
变量使用时不能加引号
改变变量的值
When changing the value of a variable, there is no need to write the keyword var, just assign the value by the assignment operator
变量的命名规则
- Only in
字母
,下划线
,数字
,$
symbols,Cannot start with a number - No keywords or reserved words
- Case sensitive, a and A are different
Variable naming rules also apply to identifier naming rules
Identifiers: functions, class names, object attributes, etc.
Excellent variable nomenclature
1,驼峰命名法
mathTestScore
2,c风格
math_test_score
变量常见错误
- Without var definition, although no error will be reported, the variable will become a global variable, which will cause scope problems
- Use a variable that is neither defined nor assigned, an error will be reported (reference error)
*type of data
数据类型简介和检测
Two data types in JS: basic type with Reference type
typeof
Operator detects the type of value or variabletypeof 5 //number typeof null //object type of NaN //number typeof undefined //undefined
Values of the null data type and undefined data type, only the respective null and undefined
基本数据类型
-
String type
Strings are spliced with + sign
The length attribute of the string can indicate the length of the string
var a='123' console.log(a.length) //输出4
String common methods
-
Number type
0 in decimals can be omitted
Scientific notation: 3e8 is the same as 3 times 10 to the 8th power
较大数或者较小数可以写成科学计数法 ,如3e8,或3e-8
NaN
special number type value, not a number -
Boolean type
-
null type
-
undefined type
复杂数据类型简介(引用数据类型)
- Array
- Object
*Expressions and operators
JS基本表达式
Arithmetic expression
Arithmetic expression