What does this javascript line do?

Possible duplicate:
What is "var _gaq = _gaq || [];" for?

var _gaq = _gaq || []; 

I'm not sure what this line does? Can someone explain this to me?

0
source share
3 answers

It is like doing

 var _gaq = _gaq ? : _gaq : []; 

This means that if _gaq installed, it will install it in _gaq , otherwise a new empty array will be installed by default.

  • var means local area
  • _gaq is the name of the variable
  • || means or

He says that if _gaq doesn't exist yet, set it to a new array, which means [] .

+3
source

It declares a variable named _gaq . If this variable is already defined and the value is true , then the string is equivalent to writing

 var _gaq = _gaq; 

If _gaq is a falsy value, then the new declare variable is an empty array.

Some links to truthfulness and falsity in JavaScript:

+2
source

It checks if _gaq is defined if it does not assign an _gaq array object.

its equivalent

 if(!_gaq){ var _gaq = []; } 
0
source

Source: https://habr.com/ru/post/1382311/


All Articles