ternary operator
(condition) ? (if true, do this) : (otherwise, do this)
ternary operator
(condition) ? (if true, do this) : (otherwise, do this)
ternary operator
// (condition) ? (if true, do this) : (otherwise, do this)
const hasAccount = true
// let userDisplayMessage
// if (hasAccount) {
// userDisplayMessage = 'Welcome Back'
// } else {
// userDisplayMessage = 'Please Sign Up'
// }
const userDisplayMessage = hasAccount ? 'Welcome Back' : 'Please Sign Up'
console.log(userDisplayMessage)
ternary operator
// It is bascially an if else statement but is an operator
// Heres a program to get the largest of 3 numbers
import java.util.Scanner;
public class Program_19{
static void main(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter Number 1 [int]: ");
int num1 = sc.nextInt();
System.out.println("Enter Number 2 [int]: ");
int num2 = sc.nextInt();
System.out.println("Enter Number 3 [int]: ");
int num3 = sc.nextInt();
int largest = (num1>num2)? ((num1>num3)?num1:num3) : ((num2>num3)? num2:num3);
System.out.println(largest+" is the largest among the 3 numbers");
}
}
Ternary Operator
condition ? expression-if-true : expression-if-false;
function findGreater(a, b) {
return a > b ? "a is greater" : "b is greater";
}
ternary operator
isMember ? '$2.00' : '$10.00'
// isMember true => output: "$2.00"
// isMember false => output: "$10.00"
// isMember null => output: "$10.00"
ternary operator
// syntax:
condition ? console.log("true") : console.log("false");
// e.g:
let n = 15;
n % 2 === 0 ? console.log("even number") : console.log("odd number");
ternary operator
if ($scope.SearchSalesOrderAndCompanyName !== undefined && $scope.SearchSalesOrderAndCompanyName != null ) {
SearchCriteria += " AND [SalesOrderNo] LIKE '%" + $scope.SearchSalesOrderAndCompanyName + "%' OR ([SO].[CompanyNameOnBill] LIKE '%" + $scope.SearchSalesOrderAndCompanyName + "%')";
}
if ($scope.FromDate !== undefined && $scope.FromDate !=null) {
SearchCriteria += " AND [SO].[SalesOrderDate] LIKE '%" + $scope.FromDate + "%'";
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us