I have quite a lot of experience in javascript, but today I came across the piece of code like this for the first time:
var _array = _array || [];
_array.push(['someItem']);
The sedond line is obious, but I don't have any idea about the first line - what is the || in there, why isn't that var _array = []; instead?
I've done some research on google but I didn't get any clue what does this strange construction really do. Can you please enlighten me?
- What is that strange construction?
- What is the difference between that and simple array declaration?
- Why would anyone use that? My eyes hurt when I look at that line of code...
EDIT:
I am perfectly aware that || is a logical OR (and of the way how logical OR works) but I have never seen it used that way - in variable declaring.