There are several methods by which you could define your IF – ELSE statement in Javascript and the usage depends on your application. The most common if-else statement looks like this,

if(<your_condition>){
// Code to be executed on IF
}
else{
// Code to be executed on ELSE
}

The above statement is the basic style of IF-ELSE statement, but what if we have a shorter style of writing if-else statements, that reduce the lines of code which could have an impact on the website or application performance?

If-else redefined

Here is an example, I have a DIV with ID #messageContainer which I need to populate via ReSTFull service myApp/service/messages. Now to populate this DIV I have to satisfy two conditions

The ReSTfull service should return JSON with key ‘message’

And if the message value in JSON is empty string, then in the DIV I have to show text ‘No messages’