Home > Article > Web Front-end > What is The Ternary Operator In JavaScript ?
Here is The syntax:
So basically , It is another way to write the conditional statements (if / else / else if ) in a much simpler way. It is especially used for the non-complex cases.
for example , instead of this:
let a = 4; if (a > 4) { console.log("ok"); } else { console.log("not ok"); }
We can just do this:
a > 4 ? console.log("ok") : console.log("not ok");
The above is the detailed content of What is The Ternary Operator In JavaScript ?. For more information, please follow other related articles on the PHP Chinese website!