jeudi 17 août 2017

ternary operator causes an error inside if statement

Why is this statement causing 'TypeError: Cannot read property 'toString' of undefined' ? I thought it'd notice thatund is undefined and just avoid the line where it tries to make a string out of und. If I remove true || from 'if' statement it works fine

let und = undefined;

 if (true || und ? und.toString() === 'anything' : false) {
    // do something
 }

Thanks

Aucun commentaire:

Enregistrer un commentaire