javascript conditional operators code example
Example 1: examples of Conditional Operator js
var age = 19;
var canDrive = age > 16 ? 'yes' : 'no';
Example 2: ternary operator in javascript
FullName: (obj.FirstName && obj.LastName) ? obj.FirstName + " " + obj.LastName : "missing values",
Example 3: js comparison operators
Javascript Comparison Operators
== Equal to
=== Equal value and equal type
!= Not equal
!== Not equal value or not equal type
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
? Ternary operator
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