Why the empty object { } and the empty array [ ] aren’t falsy, how they are truthy, by definition

26 views Asked by At

ref:https://medium.com/coding-at-dawn/what-are-falsy-values-in-javascript-ca0faa34feb4 by Dr. Derek Austin

Since I have started my development career with JavaScript this question always arise in mind how??

Truthy values include the empty object {} and the empty array [] — since they aren’t falsy, they are truthy, by definition.

let empty = []
empty ? console.log("truthy") : console.log("falsy") // truthy
empty = {}
empty ? console.log("truthy") : console.log("falsy") // truthy

where,

"" ? console.log("truthy") : console.log("falsy") // falsy
0

There are 0 answers