Can an Object be false?

前端 未结 9 1604
温柔的废话
温柔的废话 2020-12-06 04:35

Is there any way to make an object return false in javascript?

var obj = new Object();

console.log(!!obj) // prints \"true\" even if it\'s empty
         


        
9条回答
  •  难免孤独
    2020-12-06 04:49

    I think that with the first ! you are casting obj to a boolean and negating its value- resulting in true if obj is null - , and with the second ! negating it again.

提交回复
热议问题