-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
A F
  • 7,424
  • 8
  • 40
  • 52

2 Answers2

3

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

canon
  • 40,609
  • 10
  • 73
  • 97
2

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

jAndy
  • 231,737
  • 57
  • 305
  • 359