How to not return a value from the last ternary operator?
No, you can't, the last part of a ternary operator is required. To accomplish that, you need if-else blocks.
if (col_1 === 0) {
result = 0;
} else if (col_1 >= 1) {
result = col_1 - 1;
}
An alternative is using the logical operator &&
Like I said, the last part is required
(col_1 === 0) ? 0 : (col_1 >= 1 && col_1 - 1);
var col_1 = 0;
var result = (col_1 === 0) ? 0 : (col_1 >= 1 && col_1 - 1);
console.log(result);
col_1 = 5;
result = (col_1 === 0) ? 0 : (col_1 >= 1 && col_1 - 1);
console.log(result);
col_1 = 3;
result = (col_1 === 0) ? 0 : (col_1 >= 1 && col_1 - 1);
console.log(result);
col_1 = -1;
result = (col_1 === 0) ? 0 : (col_1 >= 1 && col_1 - 1);
// This case will always return false because 'col_1 < 0'
// Here you can check for that value
console.log("You need to check this situation: ", result);
.as-console-wrapper { max-height: 100% !important; top: 0; }