Is there a shorter way to use ternary logic in js when the else is “null”?
true ? console.log(true) :0; // current
I’m looking for something like
true ? console.log(true);
//or
true ?: console.log(true);
Just curious. Thanks!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try this:
This works because the
&&makes this expression into a boolean. JavaScript will try to evaluate it. If the first value is false, nothing happens because of short-circuiting. If it’s true, then it evaluates the second (theconsole.log).You can also use the
||as a quick way to doemptyin JavaScript (beware of falsey values like0and'').