Skip to content
You do not have permission to update this wiki.

js ternary

Arsen Melikyan edited this page · 14 revisions
Clone this wiki locally

The Ternary operator replaces an if/then block in a very small compact way. It's mostly used in one liners for simple tests and replacements, like this:

var x = false;
var s = x ? "yes" : "no";
console.log(s);  //→ "no"

Description

If condition is true, the operator returns the value of expr1; otherwise, it returns the value of expr2. For example, to display a different message based on the value of the isMember variable, you could use this statement:

Read more: MDN

Something went wrong with that request. Please try again.