Horje
ternary operator javascript Code Example
javascript if shorthand
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 operator javascript
// ternary operator in javascript
const x = 6;
let answer = x > 10 ? "greater than 10" : "less than 10";
console.log(answer);
// output: less than 10

// nested condition
const answer = x > 10 ? "greater than 10" : x < 5 ? "less than 5" : "between 5 and 10";
console.log(answer);
// output: between 5 and 10

// Syntax
condition ? ifTrue : ifFalse
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 
examples of Conditional Operator js

        
            
        
     var age = 19;
var canDrive = age > 16 ? 'yes' : 'no';




Javascript

Related
arange Code Example arange Code Example
array from javascript Code Example array from javascript Code Example
in compare method why we taking a and b for sorting in javascript Code Example in compare method why we taking a and b for sorting in javascript Code Example
Uncaught TypeError: $.ajax is not a function Code Example Uncaught TypeError: $.ajax is not a function Code Example
jquery autocomplete bootstrap modal Code Example jquery autocomplete bootstrap modal Code Example

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