If Else Statement

What is the use of if-else statement?
How to use if else method in javascript?


If else statement also has the same format as that of "if" statement. Only additional thing is that an else part is added to if statement. So if the condition satisfies the statements inside if part will be executed else the statement inside else part will be executed.
// set of statements if condition satisfies
// set of statements if condition fails


<script language="javascript">
var a = "1234abc";
if(a == "adcdefa"){
document.write(" inside if statement ");
document.write(" inside else part of statement ");


In the above example the condition is to check if variable 'a' equals (==) "abcdefa". The condition fails as we have assigned a as "1234abc". So the else part is executed.

Ask Questions

Ask Question