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.

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay