In looking through some code I found online, I found this peculiar line of code (Javascript):
function values(b) {
this.b = b || 0;
}
I simply can't figure out what the purpose of the ||0. If I'm not mistaken, since || returns a boolean, this value, b will always be whatever the boolean equivalent of the parameter is. If b is passed as true (ie 1 or true), then b should be true; otherwise, using one of the false values (ie. NaN, 0), this should be false. I then interpret this as the following:
b is true:
this.b = true || false; // will evaluate to true
b is false:
this.b = false || false; // will evaluate to false
I just don't see the value gained by adding ||0. Could someone please explain this to me?