[Solved] Syntactic sugar JavaScript ( If statement) Error [closed]


I try to use syntactic sugar

The conditional operator is not syntactic sugar. It’s a specific operator with a specific purpose, and you’re simply using it incorrectly. It is used for conditionally producing a value as an overall expression, one value if the condition is true and another if it’s false.

For example:

let x = input == 'one' ? 1 : 0;

This expression produces an integer value based on a condition.

What you’re trying to do is simply execute a block of code if a condition is true. And you already have the tool for that, an if statement:

if (anotherNew[numCount] == 4){
    console.log('we have removed 4');
    continue;
}

The overall lesson here is to not try to get too clever with your code. You’re using an if statement for its exact and correct purpose. The code is simple, explicit, and easy to understand at even a casual glance. These are all good things. Don’t replace them with terse and complicated code which uses tools in unintuitive ways just to save a few keystrokes.

solved Syntactic sugar JavaScript ( If statement) Error [closed]