DEV Community

Discussion on: Javascript ||, aka Why Doesn't This Work?!

Collapse
 
amt8u profile image
amt8u • Edited

Yeah, at first it can be confusing. Just one more point to add - In case of Logical OR || it behaves as a short circuit. So if you use expressions and your first expression becomes truthy, other expressions will never be evaluated. If there is a function call, it will not execute.

// if isUserMember() returns truthy value, isUserAuthorised() will never be called
var result = isUserMember(userdetails) || isUserAuthorized(userdetails);
Collapse
 
laurieontech profile image
Laurie

Absolutely