Why don't logical operators (&& and ||) always return a boolean result?

Why do these logical operators return an object and not a boolean?

var _ = (obj.fn && obj.fn() ) || obj._ || ( obj._ = {} );

var _ = obj && obj._;

I want to understand why it returns result of obj.fn() (if it is defined) OR obj._ but not boolean result.

100 thoughts on “Why don't logical operators (&& and ||) always return a boolean result?”

Leave a Comment