Home > Web Front-end > JS Tutorial > Frontend Question part-2

Frontend Question part-2

Mary-Kate Olsen
Release: 2024-12-12 20:35:14
Original
847 people have browsed it

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;

Copy after login
  • Condition: An expression that returns a True or False value.
  • 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.

Copy after login

**

  1. Null concatenation operator (??)**

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.

Copy after login
  • If left_side is null or undefined, right_side is returned.
  • Otherwise, left_side is returned.

The above is the detailed content of Frontend Question part-2. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template