It annoyed me, so I have a game and some tests, and here are my conclusions.
I will show two different script fragments that produce two different results, explaining why someone can use one over the other. The reasons for using either, however, boil down to the encoder and will be based on the effect that they want to perform.
Note. For example, for purposes, I will use actual values, not empty objects.
You can usually see the following example:
var cc = cc || 1;
This creates a new variable called cc and gives either the value of the existing (inside the same scope) variable or the default value of 1 . This method does NOT change the original variable, although in practice this will apparently affect the fact that it has changed, since you cannot subsequently refer to the original because it has the same name.
This can be tested using various variable names, for example:
var aa; alert(aa); var cc = aa || 1; alert(aa); alert(cc);
( Example ) Here you can see that aa never changes.
Next, we will consider this code:
var cc = cc = cc || 1;
This will actually change the original AND variable and create a new local one. Again, it is not easy to see effects, while variables have the same name. However, if we make the same name as above, we can see the real effect:
var aa; alert(aa); var cc = aa = aa || 1; alert(aa); alert(cc);
( Example ) This time we can see that aa changing.
In conclusion, you can never see any effect of using one over the other (with the same variable names), but I'm curious what consequences can happen if you can refer somewhere to the original, before the destination, and therefore the choice that will be used, will actually have an effect. I will see if I can find something to show this in action.