JavaScript

Logical assignment (||=, &&=, ??=)

Në shqip: Caktimi logjik

ShpjegimiSQ

x ||= 5 cakton 5 vetëm nëse x është falsy; x ??= 5 vetëm nëse është null/undefined; x &&= f(x) vetëm nëse është truthy. Mënyrë e shkurtër për vlera fillestare.

EnglishEN

x ||= 5 assigns 5 only if x is falsy; x ??= 5 only if it's null/undefined; x &&= f(x) only if it's truthy. A short way to set defaults.

Si ta mendosh

Si të mbushësh gotën vetëm nëse është bosh.

Lexoje në anglisht

Like filling the glass only if it's empty.

Shembull kodijavascript

const opsionet = {};
opsionet.gjuha ??= "sq";
opsionet.tema ||= "e errët";

Terma të lidhur