DEV Community

Supaluck Singjan
Supaluck Singjan

Posted on

Ternary Operator in JS

Ternary operator is a short-hand form in term of condition.

For example,


const score = 80;

if(score >= 80) {
console.log("Passed this step.");
} else {
console.log("Do it again.");
}

Enter fullscreen mode Exit fullscreen mode

But re-write in term of the ternary operator.


score >= 80 ? console.log("Passed this step."): console.log("Do it again.");
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
n9nyz profile image
เกมส์ออนไลน์ บนมือถือ

ติดต่อได้ที่ไหน

Collapse
 
supaluckn profile image
Supaluck Singjan

สวัสดีค่ะ ยังสนใจที่จะติดต่ออยู่ไหมคะ