-2

Possible Duplicates:
What does "options = options || {}" mean in Javascript?
null coalescing operator for javascript?  

Was reading some code and I saw this:

this.x1 = options.x1 || 0;

Never seen syntax like this before. What does it mean?

Community
  • 1
  • 1
Aakil Fernandes
  • 6,914
  • 5
  • 33
  • 49

2 Answers2

3

It's a coalesce... which means it'll assign 0 if options.x1 is falsy... and options.x1 otherwise.

canon
  • 38,844
  • 9
  • 71
  • 94
2

Let this.x1 be the value of options.x1 if options.x1 has any truthy value. Otherwise let this.x1 be 0.

jAndy
  • 223,102
  • 54
  • 301
  • 354