Anti
0
Q:

ternary operator

var age = 26;
var beverage = (age >= 21) ? "Beer" : "Juice";
console.log(beverage); // "Beer"
-1
(condition) ? (if true, do this) : (otherwise, do this)
8
//ternary operator example:
var isOpen = true; //try changing isOpen to false
var welcomeMessage  = isOpen ? "We are open, come on in." : "Sorry, we are closed.";

16
double sinc(double x) => x != 0.0 ? Math.Sin(x) / x : 1;

Console.WriteLine(sinc(0.1));
Console.WriteLine(sinc(0.0));
// Output:
// 0.998334166468282
// 1
1
isMember ? '$2.00' : '$10.00'
// isMember true =>  output: "$2.00"

// isMember false =>  output: "$10.00"

// isMember null =>  output: "$10.00"
1

  int time = 20;
string result = (time < 18) ? "Good day." : "Good evening.";

  cout << result; 
0
// C program to find largest among two
// numbers using ternary operator
 
#include <stdio.h>
 
int main()
{
    int m = 5, n = 4;
 
    (m > n) ? printf("m is greater than n that is %d > %d",
                     m, n)
            : printf("n is greater than m that is %d > %d",
                     n, m);
 
    return 0;
}
0

New to Communities?

Join the community