false == ''在js中为何判断为true

当用==操作符将false对象和其他对象进行比较的时候

  只有0和空字符串、空数组等于false;

  undefined和null对象并不等于false对象,而null和undefined是相等的。

let completed = false;

console.log(completed == 0);
console.log(completed == '');
console.log(completed == []);
console.log(completed == null);
console.log(completed == undefined);
console.log(null == undefined);

 

posted @ 2023-09-28 09:32  借你耳朵说爱你  阅读(72)  评论(0编辑  收藏  举报