0

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
  • 2
    They are truthy because the language defines them as such. Is there a compelling reason for that *not* to be the case? – VLAZ Apr 28 '22 at 10:53
  • You *may* discuss about empty arrays, but what does it mean for an *object* to be "empty"? Even "empty objects" have all sorts of properties, so when is an object really "empty"? This becomes pretty tricky pretty quickly, so they're simply truthy. – deceze Apr 28 '22 at 10:56

0 Answers0