The If statement as we all know tests a condition and then according to the result, like it is true
or false
, a particular block of code
is performed. Same as that, the JavaScript if statement is used to execute a specific block of code with the given conditions. Only if the condition evaluates to true then the defined block of code is executed otherwise not.
The if
statement tests a specified condition and then if the condition evaluates to true then the block of code defined in the if
statement gets executed otherwise the block is skipped.
In the previous statement there was no block of code defined for the false evaluation of the condition, which is defined here in else
statement. The if....else
statement also tests a condition but here the else
statement is present. The if
block's code gets executed if the given condition is true otherwise if the condition is false then the else
block's code gets executed.
JavaScript if...elseif
statement tests multiple conditions and executes different blocks of code for more than two conditions
. First, a condition specified in if
statement is tested, then if that evaluates to false, then only the elseif
's statement is tested. And if else
statement is defined and both the previous condition evaluates to false then only the else
statement gets executed.
List of color names supported by all browser »
List of character codes to display special character »
List of all language supported by all browser »
List of Country code supported by all browser »