1

var a = window.a || {};

gumpi
  • 281
  • 1
  • 4
  • 13
  • 14
    OMG, Double `|`. WHAT DOES THIS MEAN?! – Roatin Marth Oct 28 '10 at 13:13
  • +1 I am going to guess most people don't understand your reference... http://www.youtube.com/watch?v=OQSNhk5ICTI – Nix Oct 28 '10 at 13:14
  • Same thing as this - coalescing operator- http://stackoverflow.com/questions/446835/what-do-two-question-marks-together-mean-in-c – Phil Oct 28 '10 at 13:18
  • @Phil: no, it's not quite. See revision history of http://stackoverflow.com/posts/61158/revisions for someone else who used to think the same. – Roatin Marth Oct 28 '10 at 13:21
  • Similar concept though. It's operating as a coalescing operator but branches on a much wider range of values than just `null` – Phil Oct 28 '10 at 13:28

2 Answers2

7

It means a will be assigned window.a if it is not null or undefined, otherwise, it will equal an empty object

Phil
  • 157,677
  • 23
  • 242
  • 245
1

To answer the unasked question: this is used to make sure "a" will be valid.

Without it, when calling a.someFieldHere you might get exception saying "a is undefined", with such code in place you won't get such error.

It's useful when "a" is created elsewhere in some other code that not always get executed.

Kind of insurance policy. :)

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208