Horje
javascript ternary operator Code Example
javascript ternary
condition ? doThisIfTrue : doThisIfFalse

1 > 2 ? console.log(true) : console.log(false)
// returns false
javascript ternary operator
let showme || "if the variable showme has nothing inside show this string";
let string = condition ? 'true' : 'false'; // if condition is more than one enclose in brackets
let condition && 'show this string if condition is true';
ternary operator in javascript
let amount = 50;
let food = amount > 100 ? 'buy coka-cola' : 'buy just a water bottle';
console.log(food)
ternary operators js
;var eatsPlants = false
;var eatsAnimals = true
;var category = eatsPlants? (eatsAnimals? "omnivore" : "herbivore" ) : (eatsAnimals? "carnivore" : "undefined")

;console.log(category)
javascript ternary operator
// condition ? expr1 : expr2

// example:

let bar = 2
let foo = 0
let result;

result = bar > foo ? 1 : -1; // result = 2 > 0 ? 1 (true) : -1 (false);

// output: result = 1 
javascript ternary operator
condition ? ifTrue : ifFalse

//examples:

let doILikeIceCream = true
console.log(`I ${doILikeIceCream ? 'like' : 'dislike'} icecream.`)
//output: I like icecream

let doILikeIceCream = false
console.log(`I ${doILikeIceCream ? 'like' : 'dislike'} icecream.`)
//output: I dislike icecream




Javascript

Related
import img react in another file Code Example import img react in another file Code Example
short if statements in javascript Code Example short if statements in javascript Code Example
npm install --save react-native-vector-icon Code Example npm install --save react-native-vector-icon Code Example
override important css Code Example override important css Code Example
react native vector icon Code Example react native vector icon Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7