0

In many projects I commonly see OR or AND boolean operators being used on arrays or objects. What does this return? Why do developers do this? And is this acceptable as clean code?

EDIT:

Example:

var foo = foo || [];
forthe
  • 378
  • 3
  • 15
  • 1
    Can you give an example? People are _probably_ relying on what effectively amounts to a boolean conversion, but [I'll leave whether that's a good idea up to you...](https://www.safaribooksonline.com/library/view/you-dont-know/9781491905159/assets/tygr_0401.png) – Lightness Races in Orbit Feb 22 '18 at 01:27
  • That's okay in JavaScript. If the first is falsey the second value is used. That's not a boolean operator. It's an or operator. – StackSlave Feb 22 '18 at 01:36
  • I was asking for specific behavior with non-primitive types, i already know how the || operator works with primitive types. – forthe Feb 22 '18 at 01:47

0 Answers0