2
var DYN_WEB = DYN_WEB || {};

I saw above code in one js file

Question:

what does this mean?

user2294256
  • 1,029
  • 1
  • 13
  • 22

3 Answers3

6

if DYN_WEB is not null it will take the value already set for DYN_WEB else assign an empty object to it.

codetantrik
  • 315
  • 2
  • 9
1

This is shorthand for

if ( ! DYN_WEB ) {
  DYN_WEB = {}
}

or

var DYN_WEB = DYN_WEB ? DYN_WEB : {}
Yang
  • 8,580
  • 8
  • 33
  • 58
0

it means if the variable DYN_WEB has a value which is evaluated to binary true, then keep that value, otherewise assign {} to it. The latter will happen if the previous value of the variable is 'falsy' ie. one of the false, null, undefined, NaN, 0, "", [] or {} and in case it's not defined.

0xc0de
  • 8,028
  • 5
  • 49
  • 75