All Objects are Truthy Values

All Objects are Truthy Values

Converting any object into a boolean gives the true value. Here are a few examples.

Boolean({}) //true
Boolean([]) //true
Boolean(new Date()) //true

Even the wrapper object for the false value returns true.

const falseWrapper = new Boolean(false);
Boolean(falseWrapper); //true

All objects are considered to be truthy values. They are evaluated to true in a test condition.

if({}){
console.log('Truthy');
}else {
console.log('Falsy');
}
//'Truthy'

Negating an object using the Not (!...

 •  0 comments  •  flag
Share on Twitter
Published on June 21, 2021 01:02
No comments have been added yet.