JavaScript supports the following types of if..else statement
The if statement is the basic control statement that check the condition if condition is true then block of statement to be execute.
if (condition) { Statement(s) to be executed if condition is true. }
var check = 5; if(check>4) { document.write('eligible for gratuity'); } //Output //eligible for gratuity
The if...else statement(s) executes some code if a condition is true and another code if that condition is false.
if (condition) { Statement(s) to be executed if condition is true. } else{ Statement(s) to be executed if condition is false. }
var check = 18; if(check>17) { document.write('eligible for vote'); } else{ document.write('Not eligible for vote'); } //Output //if var check value is 18 then eligible for vote //if var check value is 18 then Not eligible for vote
The if...else if... statement used for more than two conditions to be checked
if (condition) { Statement(s) to be executed if condition is true. else if (condition) { Statement(s) to be executed if condition is true. } else{ Statement(s) to be executed if no condition is true. }