Javascript - Ternary operator ? :
📖 Read the lesson
Code Life
By Pierre Marsaa
The Ternary Operator
Sometimes an
if
/
else
feels heavy for a tiny decision. JavaScript has a compact shortcut: the
ternary operator
. It fits a whole decision on one line.
Loading editor...
↗️
Loading editor...
↶
▶️ Run
↷
Read it like a question: "is
aquachuHP >
50
? If yes, take
"healthy"
, if no, take
"weak"
". Change the HP to
30
and run again.
Verify