My searching for an answer to that question was fruitless, I 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 "Boole 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
at all times)
- law of non-contradiction (nothing can be and not be at the same time)
- law of the excluded third (either you are true or you are false, it cannot be something in between, a third value)
Read more here.
The operators used are the &&
"And" (and in English is less ambiguous) and the ||
"OR" (in English or).
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 "OR" 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 he can already determine the value of the boolean expression by looking only at the first operand, he does not even go back to calculating the value of the second operand. The name of this strategy of not computing unnecessary things is "short circuit".
But in this case you’re not working with truth values. Or are you? See, in Javascript, they take it more lightly about the type of the object. You may not be dealing with booleans, but your values may be "true" or "Falsiformes" (not to be confused with "sickle cell").
A thing with "true form" or "true form" is called Truthy in Javascript and, for everything involving boolean expressions, are considered true. Already the ones with "false form" or "false form" are the falsy and are for all purposes equivalent to false boolean.
You can find more about these terms in the answers of this issue.
So, what’s going on?
In the case of "E", case window.RM
be it Truthy, the expression will return {}
, otherwise will return window.RM
same. How this is being assigned in the variable window.RM
, this seems to be a way to "zero" the object if it has some value.
In the case of "OR", it seems more like a kind of initialization of the object window.RM
, for its value is only superscripted with {}
in case he’s already falsy, otherwise (if Truthy) it does not have its altered value.
You know the term falsy? Help these operators understand
– Jefferson Quesado
I don’t know....
– Luiz Felipe
I’m sure this has already been answered, but I can’t research it now.
– Maniero
About falsy and Truthy: https://answall.com/q/271693/64969
– Jefferson Quesado
I get it. But what does that have to do with my question?
– Luiz Felipe