DEV Community

Cristian Fernando
Cristian Fernando

Posted on • Edited on

3 2

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

¿Qué imprime este código?

console.log(+true);
console.log(!"Lydia")
Enter fullscreen mode Exit fullscreen mode

A: 1 y false
B: false y NaN
C: false y false

Respuesta en el primer comentario.


Top comments (1)

Collapse
 
duxtech profile image
Cristian Fernando

La respuesta es:
A: 1 y false

El el primer caso, el operador + intenta convertir a number al valor true, por coerción de tipos javascript infiere a true como 1.

En el segundo caso, intentamos negar un string, dicho string es un valor truthy, por ende, nuevamente por coerción de tipos javascript infiere al string "Lydia" como true, y la negación de true es false

Cloudinary image

Zoom pan, gen fill, restore, overlay, upscale, crop, resize...

Chain advanced transformations through a set of image and video APIs while optimizing assets by 90%.

Explore

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay