0

As in here for example:

var h , aa = aa || {} , m = this ,

What's the meaning of "|| {}" ?

Annya
  • 1

3 Answers3

5

It prevents you object from being undefined. E.g. if you write:

a = B || {};

and B will be undefined --> you will assign empty object instead of FALSY value (undefined).

Sum up: if value is "falsy value" assign empty object.

Here you have all falsy values:

  • undefined
  • null
  • NaN
  • boolean type FALSE value
  • simply '0' as number
  • empty string variable
0
aa = aa || {}

This is setting a default value for the variable aa. If aa isn't "truthy" at the time this line executes, it will set it to {}.

amphetamachine
  • 27,620
  • 12
  • 60
  • 72
0

It's a default initialization in case aa is falsy. If aa is falsy (undefined, 0, empty string,...), aa is initialized to an empty object.

fikkatra
  • 5,605
  • 4
  • 40
  • 66