var a = [1,4,5]; var e = a.length--;
Here e variable will contain 5. But if I do:
var e = a.length-=1;
Here e will contain 2 the number of elements array.
So the first is a language ‘tip’ to simulate a pop() array methods?
In the language syntax doing:
a--
or
a-=1
is semantically the same.
is the same as
whereas
is the same as
and
In other words: x– returns the value before decreasing whereas –x (and x -= 1) returns the value after decreasing. All these code snippets pop the last element off the array a.
Note that in the first example,
e = a.length--, e will have the value 3, not 5, therefore it is not the same asa.pop().