Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Ternary Expressions in JavaScript

let memberType = 'basic';
let price = memberType === 'basic' ? 5 : 10;

In the example, the condition that is evaluated is whether memberType === 'basic'. 
If this condition is true, then price will be 5, and otherwise it will be 10. 
The equivalent long-hand conditional expression would be:

let memberType = 'basic';
let price;

if (memberType === 'basic') {
  price = 5;
} else {
  price = 10;
}
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #Ternary #Expressions #JavaScript
ADD COMMENT
Topic
Name
4+7 =