JavaScript隐式转换
+和-
"37"-7 // 30 字符串变数字
"37"+7 //377
"100"-0 //100 字符串变数字
100+"" // "100" 数字变字符串
a==b(弱等于)
"1.23"==1.23
0==false
null==undefined
new Object()==new Object()
[1,2]==[1,2]
a===b(严格等于)
1.类型不同,返回false
类型相同:
null===null
undefined===undefined
NaN!=NaN
new Object !=new Object
类型检测
typeof
instanceof
Object.prototype.toString
constructor
duck type
特殊运算符
名称 | 运算符 |
---|---|
条件运算符 | c?a:b |
逗号运算符 | a,b |
delete | delete obj.x |
in | “document” in window |
instanceof | obj instanceof Func |
new | new ClsName() |
this | return this; |
typeof | typeof 100 |
void | void 0 |