DEV Community

BekmuhammadDev
BekmuhammadDev

Posted on

Frontend Question part-2

** Uchlik operator (?:)**
Uchlik operator shartlarni tekshirishda ishlatiladi va quydagicha ishlaydi.

let result = shart ? true_holat : false_holat;

Enter fullscreen mode Exit fullscreen mode
  • Shart: True yoki False qiymat qaytaradigan ibora.
  • Agar shart true bo‘lsa, true_holat qaytadi; aks holda, false_holat qaytadi.

  • Shartli operator (True yoki False qaror qabul qiladi)

  • Uch qismdan iborat (shart, true, false)

Misol:

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.

Enter fullscreen mode Exit fullscreen mode

**

  1. Nullish birlashtiruvchi operator (??)**

Bu operator null yoki undefined qiymatlarni tekshirish uchun ishlatiladi. Agar chap tomondagi qiymat null yoki undefined bo‘lsa, o‘ng tomondagi qiymat qaytariladi.

misol:

let username = null;
let defaultName = "Mehmon";
let natija= username ?? defaultName;
console.log(natija); // "Mehmon" username null qiymatga teng va u chapda joylashgan natija Mehmon.

Enter fullscreen mode Exit fullscreen mode
  • Agar chap_tomon null yoki undefined bo‘lsa, o‘ng_tomon qaytadi.
  • Aks holda, chap_tomon qaytariladi.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more