方法一:
var
a = {};
if
(!a){ console.log(1);}
else
if
(a ==
null
) { console.log(2);}
else
{ console.log(3);}
结果为:3
方法二:
var
b = {};
if
(b == {}){ console.log(4);}
if
(b ==
'{}'
) { console.log(5);}
if
(
typeof
(b) ==
'object'
) { console.log(6);}
方法三:
var
c = {};
if
(JSON.stringify(c) ==
"{}"
){ console.log(7);}
方法四:
var
d = {};
var
e = {id:111};
if
(d.id){ console.log(8);}
if
(e.id){ console.log(9);}