what is a terniary operator node js code example

Example 1: ternary function javascript

var variable;
if (condition)
  variable = "something";
else
  variable = "something else";

//is the same as:

var variable = condition ? "something" : "something else";

Example 2: Ternary Operator

condition ? expression-if-true : expression-if-false;

function findGreater(a, b) {
  return a > b ? "a is greater" : "b is greater";
}

Example 3: ternary operator in javascript

FullName: (obj.FirstName && obj.LastName) ? obj.FirstName + " " + obj.LastName : "missing values",

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 + "%'";
        }

Tags:

Misc Example