0

There's a code written in javascript I have to re-use/modify and there's a line I don't understand:

var source, data = [];        
for (var id in this.target.target.layerSources) {
    source = this.target.target.layerSources[id];
    data.push([id, source.title || id, source.url]); //I don't understand this line
}

I looked it up but I don't find any example/explanation.

Michael De Keyser
  • 787
  • 1
  • 17
  • 45

1 Answers1

4

You are almost right, it means if source.title is falsy, it will take the variable id instead.

Falsy values are :

false
''
0
null
undefined
NaN
axelduch
  • 10,769
  • 2
  • 31
  • 50
Karl-André Gagnon
  • 33,662
  • 5
  • 50
  • 75
  • 2
    Ohhh alright. I assumed "id, source.title" and "id, source.url" were the two sides of the OR but it's just source.title and id. It makes so much more sense. Thanks mate. – Michael De Keyser Jun 13 '14 at 14:21