Home >Web Front-end >JS Tutorial >Frontend Question part-2
** Ternary operator (?:)**
The ternary operator is used to check conditions and works as follows.
let result = shart ? true_holat : false_holat;
If the condition is true, true_state is returned; otherwise, false_status is returned.
Conditional operator (decides True or False)
Consists of three parts (condition, true, false)
Example:
let age = 18; let natija = age >= 18 ? "Kirish mumkin" : "Kirish mumkin emas"; console.log(natija); //kirish mumkin chunku age 18 ga teng 18 = 18 ga true holat.
**
This operator is used to check for null or undefined values. If the value on the left is null or undefined, the value on the right is returned.
example:
let username = null; let defaultName = "Mehmon"; let natija= username ?? defaultName; console.log(natija); // "Mehmon" username null qiymatga teng va u chapda joylashgan natija Mehmon.
The above is the detailed content of Frontend Question part-2. For more information, please follow other related articles on the PHP Chinese website!