DEV Community

Cristian Fernando
Cristian Fernando

Posted on

4 2

Paracetamol.js💊| #99: Explica este código JavaScript

Explica este código JavaScript

console.log(([] || {}) && (undefined ?? "") || null);
console.log(0 || false || Symbol("hola") || 2n);
console.log(typeof (undefined || null || 0 || ("0" ?? 0)));
console.log((() => "hola")() || (false && true));
Enter fullscreen mode Exit fullscreen mode

A. {}, 2n, number, false
B. undefined, Symbol("hola"), string, "hola"
C. null, Symbol("hola"), string, "hola"
D. null, 0, number, true

Respuesta en el primer comentario


Respuesta:
C. null, Symbol("hola"), string, "hola"

El operador || solo se ejecuta si el primer operando es un valor falsy.
El operador && solo se ejecuta si el primer operando es un valor truthy.
El oeprador ?? solo se ejecuta si el primer operando es null o undefined

Dicho todo esto y conociendo los valores truthy y los valores falsy no debería costarte llegar a que la respuesta correcta es C.

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

👋 Kindness is contagious

If this post resonated with you, feel free to hit ❤️ or leave a quick comment to share your thoughts!

Okay