DEV Community

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

z00md profile image
z00md • Edited on

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);
laurieontech profile image
Laurie Author