The ?
is the conditional ternary operator, you can express the same with an if
statement like this:
labels: {
formatter: function () {
if (this.value > 0) {
return ' + ' + this.value + '%';
} else {
return '' + this.value + '%';
}
}
},
It works like: If the condition is true, execute the first argument, if not the second.
CONDITION ? EXPRESSION_ON_TRUE : EXPRESSION_ON_FALSE
Some other examples how this operator can be used:
// assign 'a' or 'b' to myVariable depending on the condition
var myVariable = condition ? 'a' : 'b';
// call functionA or functionB depending on the condition
condition ? functionA() : functionB();
// you can also nest them (but keep in mind this can become difficult to read)
var myVariable = cond ? (condA ? 'a' : 'b') : (condB ? 'c' : 'd')
Also, this operator is nothing special that you can only use with the jQuery library, you can also use it with plain JavaScript.