Conversion of js true and false empty array

let obj ={
        a :true,
        b:[]
    }
if(obj.a && obj.b){
  console.log(324)
}
//324 obj.b

//
obj.b => [] => Boolean([]) => true
//
[]===[]
//false

* *

< H2 > add: how can I modify it if I want to implement the usual function that only executes 1 for true? This array is sometimes a non-empty array < / H2 >

* *

Oct.11,2021

[] typeof = > "object" and then convert to true
null except for objects

clipboard.png


if==;
ifObjecttrueTo Boolen;
==ToPrimitive;
[]===[]:[]false




obj.b

: [] == false true
https://www.cnblogs.com/nanch...


obj.a = true
obj.b = [] true







true

clipboard.png


this is the difference between js and python. Empty arrays and empty objects are all true


any object that converts Boolean to true

Menu