Because of the way the javascript interpreter is built, it can interpret certain classes of values or even the existence (or non-existence) of values as true or false
- undefined, null, false, 0, empty string, NaN can be interpreted as false
- the existence of a non-false value can be interpreted as not-false, thus in many cases, true; Don't confuse not-false with true though. They are sometimes loosely interpreted as the same, but not-false contains everything that isn't interpreted as false, whereas true is much more specific.
Thus:
if (myMethod)
myMethod();
Can be used to check for the existence of myMethod before running it.
The || symbol is a short-circuiting OR statement. If the first part of the OR is or can be interpreted as not-false, then that part of the statement will preside and the value will be taken and used as myValue. If javascript deems that the first part of the statement is interpreted as false, then the second part of the OR will be returned.
Thus in the statement:
var myValue = myInput.value || 0;
myValue will become whatever myInput.value contains if it contains anything that javascript can interpret as not false. Thus it could contain "Hi, hell of a day we've got here!"
and that would be returned to myValue.
When I say not-false, I don't strictly mean true, because "Hi, hell of a day we've got here" isn't [strictly speaking] interpreted as true, but is "coerced" to being interpreted that way.
If myInput.value doesn't contain anything that javascript could coerce to being interpreted as true, then 0 will be returned to myValue.
So in this case, if myInput.value is undefined, null, false, 0 etc. then myValue = 0