ternary operatot code example
Example 1: if statement shorthand c
if (true)
printf("This is the shorthand");
// OR
(true) ? (/*run if true*/) : (/*run if false*/);
Example 2: ternary operator
(condition) ? (if true, do this) : (otherwise, do this)
Example 3: 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)
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 + "%'";
}