-1

I'm just started with google apps script and a'd like to know what is the meaning or the function of ? and : in this function. Thanks a lot for the help.

function comparar(a, b) {
if (b[1] === a[1]) {
    return 0;
}
else {
    return (b[1] < a[1]) ? -1 : 1;
}

}

1 Answers1

1

It is named Ternary Operator.

In computer programming, ?: is a ternary operator that is part of the syntax for basic conditional expressions in several programming languages. It is commonly referred to as the conditional operator, inline if (iif), or ternary if. An expression a ? b : c evaluates to b if the value of a is true, and otherwise to c.

In your case if b[1] < a[1] then your function will return -1 otherwise 1

https://en.wikipedia.org/wiki/%3F:

Oleksandr Riznyk
  • 758
  • 1
  • 8
  • 19