jeudi 18 juin 2020

JavaScriptClass : Simple conditional (ternary) Operator returns wrong result

I have the following code, using a ternary operator to terun if a value is true or false.

My expected result of would be pp is true, however i get the result that it is false.

How can this be? This doesnt make sense for me.

const test = (x) => {
    (x === 1) ? true : false;
}


let pp = test(1); // SHOULD BE TRUE


if (pp) {console.log('pp is true')}
else {console.log('pp is false')}; // PRINTS FALSE, BUT SHOULD BE TRUE

Aucun commentaire:

Enregistrer un commentaire