typeof 运算符
1 2 3 4 5 6 7 8
| typeof undefined typeof 'abc' typeof 123 typeof true typeof {} typeof [] typeof null typeof console.log
|
变量运算 - 强制类型转换
字符串拼接
1 2
| var a = 100 + 10 var b = 100 + '10'
|
当使用减运算时:
== 运算符
1 2 3
| 100 == '100' 0 == '' null == undefined
|
==与===的区别:===是严格等于,只有类型完全相同才会返回true
1 2 3 4
| null === null undefined === undefined null === undefined NaN === NaN
|
什么时候用==什么时候用===:jQuery源码中推荐写法,只有下述情况才用==,其他时候都用===。
if语句
1 2 3 4 5 6 7 8
| var a = true; if(a) {
var b = 100; if(b) {
var c = ''; if(c) {
|
if中被判定为false的几个值:0,NaN,'',null,undefined
逻辑运算
1 2 3 4 5 6 7
| console.log(10 && 0) console.log('' || 'abc') console.log(!window.abc)
var a = 100; console.log(!!a)
|