ternary meaning code example
Example 1: ternary operator
(condition) ? (if true, do this) : (otherwise, do this)
Example 2: ternary operator
const hasAccount = true
const userDisplayMessage = hasAccount ? 'Welcome Back' : 'Please Sign Up'
console.log(userDisplayMessage)
Example 3: ternary operator
condition ? console.log("true") : console.log("false");
let n = 15;
n % 2 === 0 ? console.log("even number") : console.log("odd number");
Example 4: 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 + "%'";
}
Example 5: ternary
isMember ? '$2.00' : '$10.00'
Example 6: ternary
let greeting = ( isBirthday ) ? 'Happy birthday Mrs. Smith — we hope you have a great day!' : 'Good morning Mrs. Smith.';