if ternary operator 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: conditional operator
var age = 26;
var beverage = (age >= 21) ? "Beer" : "Juice";
console.log(beverage);
Example 4: javascript ternary operator
var isOpen = true;
var welcomeMessage = isOpen ? "We are open, come on in." : "Sorry, we are closed.";
Example 5: ternary operator in javascript
FullName: (obj.FirstName && obj.LastName) ? obj.FirstName + " " + obj.LastName : "missing values",
Example 6: 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 + "%'";
}