1

Maybe a stupid question for you, but I found a site where this source was given with no further info. I searched with google but I got no useful suggestions.

I want to know what this line actually does. Give me a link or the name of this function? so I can look it up myself.

Thank you :)

y += (x<= uz ? 1.0 : 0.0) * radius;

I know what += and * do, but the rest is a huge questionmark

Pris0n
  • 350
  • 1
  • 5
  • 24
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator – Alex K. Jun 24 '13 at 12:54

2 Answers2

3

It is a ternary operator.

Conditional (Ternary) Operator (?:)

Returns one of two expressions depending on a condition.

test ? expressionIfTrue : expressionIfFalse

With your code it is the same as:

if (x<uz) {
  y += radius;
} else {
  y += 0;
} 
Umur Kontacı
  • 35,403
  • 8
  • 73
  • 96
epascarello
  • 204,599
  • 20
  • 195
  • 236
2

That is a ternary operator. Basically this translates to:

var y;
// ...

if( x <= uz ) {
  y += 1.0 * radius;
} else {
  y += 0.0 * radius;
}
Sirko
  • 72,589
  • 19
  • 149
  • 183