What does this mean in var definition:
var array = array || [];
... and next two parts of javascript are equal each other?
var array = array || [];
array.push([1],[2]);
array.push([3]);
=
var array = array.push([1],[2],[3]) || [];
?
It is equivalent to this,
var array;
if(array){
array = array;
} else {
array = [];
}
Just in a much shorter form.
In the second part, No those two are not equivalent.
array.push([1],[2],[3])
needs to be executed no matter what, if you use || [] it will not be added.
In other words, you start with this,
var array;
if(array){
array = array;
} else {
array = [];
}
array.push([1],[2],[3]);
And you then modified it to this,
var array;
if(array){
array = array;
array.push([1],[2],[3]);
} else {
array = [];
}
It means that if array is a falsy value (undefined, null etc.) - the value that will be assigned to the var array is an empty array - [];
EDIT:
the second part of your question - no these are not equivalent.
For instance, when array is undefined:
var array = array.push([1],[2],[3]) || [];
this will throw an exception.
This:
var array = array || [];
array.push([1],[2]);
array.push([3]);
will not.