Ad
  • Custom User Avatar
  • Custom User Avatar

    It's called a ternary operation; it's a short-hand if else statement. The syntax is as follows: Boolean ? True : False. It's a pretty old operation and is used in Java, JavaScript, CoffeeScript, C++, Ruby and others.

    The code above arr[5]=="loses" ? one-two : one+two; first looks at the boolean expression before the question mark and if it evaluates as true, then it look at the first statement after the question mark. If the boolean expression is false, it will look at the second statement after the question mark.

    It's equivalent to

    if (arr[5] == "loses")
      return one-two
    else
      return one+two
    
    

    For more information, you can read about it here, and here.