My searches for an answer to this question were unsuccessful, you should be using the wrong words. So there goes an answer
These operators you refer to are boolean operators. This means that they operate within the mathematical universe called "Boolean Algebra". This algebra differs from our traditional algebra because it does not work with numbers, but only with two values.
This algebra works on 3 axioms:
- identity law (
a == a
always)
- law of non-contradiction (nothing can be and not be at the same time)
- Third party's deleted law (either you are truthful or false, can not be something in between, a third value)
Read more here .
The used operators are &&
"E" and "%" of% "OU".
They work in a certain way, which can be seen in truth tables . Note how the result depends on the first variable.
- If the first variable is false, the "E" will be false as a whole; otherwise it will be the value of the second variable
- If the first variable is false, the "OU" will have the value of the second variable; otherwise, just know that the first variable is true
So JavaScript works like this for your Boolean operators. Even if it can already determine the value of the Boolean expression by looking only at the first operand, it does not even go beyond calculating the value of the second operand. The name of this strategy of not computing unnecessary things is "short circuit."
But in case you are not working with true values. Or is? See, in JavaScript, they get more light on the type of the object. You may not be dealing with Booleans, but your values may be "true-malformed" or "falsiform." (Not to be confused with "sickle-cell").
One thing with "true form" is called truthy in JavaScript, and for everything involving Boolean expressions, they are considered to be true.
You can find out more about these terms in answers .
So what's going on?
In case of "E", if ||
is truthy , the expression will return window.RM
, otherwise it will return {}
itself. Since this is being assigned to the variable window.RM
, this seems to be a way to "zero" the object if it has any value.
In the case of "OU", it seems like a kind of initialization of the object window.RM
, since its value is only overwritten with window.RM
if it already falsy , otherwise is truthy ) it does not have its value changed.