So I know
variable && runTrue();
really means
if(variable){
runTrue();
}
Then is there a more simplified way to write
if(variable){
runTrue();
}else{
runFalse();
}
instead of if-else?
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.
Yes, I found out that this would do the same thing as a normal
if-else:It is 2 characters shorter (still better than nothing) and tested in jsPerf that usually
Short-circut evaluation - falsefor most of time is faster than the normal way of doing this.But of course, you can always use
variable?runTrue():runFalse();.