if operator javascript code example
Example 1: or statment javscript
if (x === 5 || x === 8)
console.log("x is eaqual to 5 OR 8")
Example 2: ternary operator in javascript
FullName: (obj.FirstName && obj.LastName) ? obj.FirstName + " " + obj.LastName : "missing values",
Example 3: if javascript
if (a > 0) {
result = 'positive';
} else {
result = 'NOT positive';
}
Example 4: javascript conditional evaluation
if ( expression )
Here are some expressions and their result
Undefined: false
Null: false
Boolean: the result equals the input argument (no conversion)
Number: false if the argument is +0, -0, or NaN; otherwise true
String: false if the argument is an empty string (length = 0);
otherwise true
Object: true