dimanche 28 mars 2021

Boolean logic interpretation in google chrome console

I'm having difficulties figuring out why the code below doesn't work as expected:

const userInput = prompt("Enter something");

if (userInput) {
    console.log("TRUTHY");
} else {
    console.log("FALSY");
}

I keep getting "TRUTHY" no matter what I do. I understand the logic of this code and even when running the source file from the class I'm not getting the expected output.

I should get "FALSY" whenever the input is: 0, null, undefined, an empty string or NaN.

What am I doing wrong? Thank you.




Aucun commentaire:

Enregistrer un commentaire