Home > Web Front-end > JS Tutorial > body text

What is The Ternary Operator In JavaScript ?

WBOY
Release: 2024-08-16 06:18:32
Original
458 people have browsed it

Here is The syntax:
What is The Ternary Operator In JavaScript ?
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");
}
Copy after login

We can just do this:

a > 4 ? console.log("ok") : console.log("not ok");
Copy after login

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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template