- 变量
1 2 3 4 5 6 7 8 9 10
| var 王者农药 = 倔强青铜;
i = 1;
var i = 1;
let i = 1;
'use strict';
|
- number
js不区分小数和整数
1 2 3 4 5 6
| 123 123.1 1.123e3 -99 NaN Infinity
|
- 字符串
1 2 3 4 5 6 7 8 9 10 11 12
| 'abc' "abc" 'a\'' let name = "qp"; let msg = '你好, ${name}' str.length
str.toUpperCase() str.toLowerCase() indexOf() substring() 等等等等等方法
|
布尔值
true/false
逻辑运算
- 比较运算符
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| = == ===
NaN === NaN
``` //浮点数不要直接比较, 精度损失! Math.abs(1/3 - (1 - 2/3)) < 0.00000001
6. null 和 undefined null 空值 undefined 未定义
7. 数组 java的数组必须是相同类型的对象, js不需要这样, 类似py var arr[1, 2, 3, 'world', null, true]; new Array(1, 2, 3, 'hello'); 取数组下标越界了, 就会undefined
8. 对象 对象是大括号, 数组是中括号 ```js var person = {
}
|
Author:
Qin Peng
Permalink:
https://qpwlkq.github.io/2021/03/26/javascript-no.2/
License:
Copyright (c) 2020 BY QPWLKQ LICENSE
Slogan:
每一个不曾起舞的日子, 都是对生命的辜负