Operators in JavaScript: ===, &&, || and ??

Strict equality, truthy/falsy values, short-circuiting, the ?? (nullish) operator, the ternary and optional chaining ?., with interactive labs.

La regla de oro: usa siempre === (compara valor y tipo, sin conversiones). Y aprende qué valores son falsy: false, 0, "", null, undefined, NaN. Todo lo demás es truthy.

== vs ===

truthy / falsy and short-circuiting

a && b: si a es falsy, devuelve a; si no, devuelve b. a || b: si a es truthy, devuelve a; si no, b. No devuelven true/false, ¡devuelven uno de los valores!

?? (nullish) and ?.

a ?? b devuelve b solo si a es null o undefined (a diferencia de ||, que también salta con 0 o ""). obj?.prop lee prop sin petar si obj es nulo.

The ternary operator

const edad = 20;
const tipo = edad >= 18 ? "mayor" : "menor";

Check what you've learned