[removed] is this a conditional assignment?

后端 未结 4 702
猫巷女王i
猫巷女王i 2021-02-05 12:45

From the google analytics tracking code:

var _gaq = _gaq || [];

how does this work?

Is it a conditional variable value assignment? Is i

4条回答
  •  悲哀的现实
    2021-02-05 13:17

    The or operator (||) will return the left hand side if it is a true value, otherwise it will return the right hand side.

    It is very similar to your second example, but since it makes use of the var keyword, it also establishes a local scope for the variable.

提交回复
热议问题