vendredi 11 septembre 2020

Why a complete boolean statement is not required in if statement?

I am wondering why "if (ethos[name])" is already enough? Coz I would write if(name=ethos[name]). What does it mean? Thank you.

var ethos = {
    achilles: "glory",
    aeneas: "duty",
    hades: null // Beyond human understanding
}

function printEthos (name) {
    if (ethos[name]) {
        console.log(ethos[name]);
    } else {
        console.log(name + " has no recorded ethos.");
    }
}```

Aucun commentaire:

Enregistrer un commentaire