Logical AND (&&
) and OR (||
) operators --- who knew they could trick us like this :)
Their definition, for JS (according to this ex
It's just how they work. It's not a bug:
Returns expr1 if it can be converted to false; otherwise, returns expr2
This means you can use "default values", like this:
function someFunc(passedParameter){
var newValue = passedParameter || 1337
}
Or run functions when conditions are met:
var myBool = true;
myBool && someFunc(); // someFunc will only be evaluated if `myBool` is truthy
More info on truthy / falsy