While reading JavaScript codes, you may find “?” operator in a high frequency.
(condition) ? truePart : falsePart;
is rough equivalent of:
if (condition) {
truePart;
}
else {
falsePart;
}
The same shorthand method can also be used to set variables. For instance: myNewVariable = (condition) ? trueValue : falseValue;
is equivalent to:
if (condition) {
myNewVariable = trueValue;
}
else {
myNewVariable = falseValue;
}