For example suppose I have
var myVar;
If I do
console.log((myVar != undefined) && true);
It returns false as expected. Is it possible to do something closer to
console.log(myVar && true);
It’s much less verbose. At the moment the above returns undefined I would like false.
If I’m understanding you correctly, you want to turn
undefinedandfalseintofalseandtrueintotrue. If so, this should work fine:Each
!converts the value to a boolean and returns the opposite. The opposite of the opposite is the same as the original, except for that “converts to a boolean” part, which is exactly what you want.For more information, see this question.