JS Ternary - ashish9342/FreeCodeCamp GitHub Wiki

JavaScript Ternary Operator

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

⚠️ **GitHub.com Fallback** ⚠️