2020-12-29 18:18:08 +08:00
|
|
|
|
# 3变量
|
2020-12-16 15:58:59 +08:00
|
|
|
|
|
|
|
|
|
> javascript的变量是不区分类型的
|
|
|
|
|
|
|
|
|
|
## 创建变量
|
|
|
|
|
|
|
|
|
|
`var 变量名;`
|
|
|
|
|
|
|
|
|
|
`var 变量名 = 变量值;`
|
|
|
|
|
|
|
|
|
|
没有值的时候 是创建一个变量 但它的值是`undefined` 这也是默认变量的值 所有没有赋值的变量都是`undefined`
|
|
|
|
|
|
|
|
|
|
赋值了之后就变成你赋值之后的值;
|
|
|
|
|
|
|
|
|
|
> 实际演示 并且介绍console.log()
|
|
|
|
|
|
|
|
|
|
## 变量类型
|
|
|
|
|
|
2020-12-18 10:55:06 +08:00
|
|
|
|
- undefined
|
|
|
|
|
- boolean
|
|
|
|
|
- string
|
|
|
|
|
- number
|
|
|
|
|
- object
|
|
|
|
|
- function
|
|
|
|
|
|
|
|
|
|
## typeof
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## undefined
|
|
|
|
|
|
|
|
|
|
任何只声明没有赋值的变量都是undefined
|
|
|
|
|
|
|
|
|
|
## null
|
|
|
|
|
|
|
|
|
|
空对象指针
|
|
|
|
|
|
|
|
|
|
## boolean
|
|
|
|
|
|
|
|
|
|
只有 true 和 false
|
|
|
|
|
|
|
|
|
|
## number
|
|
|
|
|
|
|
|
|
|
- 整数 121212
|
|
|
|
|
- 小数 1.12121
|
|
|
|
|
- 八进制 012475
|
|
|
|
|
- 十六进制 0x2474ab
|
|
|
|
|
|
|
|
|
|
> 浮点数精度问题
|
|
|
|
|
|
|
|
|
|
### NAN
|
|
|
|
|
|
|
|
|
|
非常特殊的一个值 应该有值返回的时候但没有值返回 注意 : nan != nan
|
|
|
|
|
|
|
|
|
|
### parseInt
|
|
|
|
|
|
|
|
|
|
转化到数字
|
|
|
|
|
|
|
|
|
|
> 注意8进制
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## string
|
|
|
|
|
|
|
|
|
|
- 用‘’ 或 “” 定义
|
|
|
|
|
- 单引号开头必须单引号结尾
|
|
|
|
|
- 双引号开头必须双引号结尾
|
|
|
|
|
|
|
|
|
|
### 字符字面量 了解就行
|
|
|
|
|
|
|
|
|
|
- \n
|
|
|
|
|
- \t
|
|
|
|
|
- \b
|
|
|
|
|
- \r
|
|
|
|
|
- \f
|
|
|
|
|
- \\\
|
|
|
|
|
- \\'
|
|
|
|
|
- \\"
|
|
|
|
|
- \\xnn
|
|
|
|
|
- \\unnnn
|
|
|
|
|
|
2020-12-21 09:26:16 +08:00
|
|
|
|
### .length
|
|
|
|
|
|
|
|
|
|
### .toString()
|
|
|
|
|
|
|
|
|
|
## object
|
|
|
|
|
|
|
|
|
|
### 创建
|
|
|
|
|
|
2020-12-21 10:33:16 +08:00
|
|
|
|
`new Object() 或者 {}`
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## ES6新增
|
|
|
|
|
|
|
|
|
|
- let 变量
|
|
|
|
|
- const 常量
|