Where foo is a specific variable, why is the following code:
var array = [].push(foo);
when output is 1 ?
From my tests, array output will simply output the length of the array.
So the code:
var array = [10,20].push(foo);
will give a value of 3 .
As a related question (and to clarify what my code should have done), why doesn’t it intuitively do what it does, i.e.:
var array = [];
array.push(foo);
where is the output of the array giving the expected result [foo] ?
source
share