JavaScript tutorial-if else


JavaScript conditional statement: if else

A conditional statement is a statement that computer programming language used to decide which code has to be run when the true condition is met or which code has not to be run when the true condition is not met.

-if/else Statement

If statement will check the condition. If it is true, it will execute the statements that follows it. Otherwise, it will execute the statements in else statement.

if (condition) {
                 Statement1
                 statement2
                       }

or

 

if (condition) {
 
                 Statement1
                 statement2
                        }
else {
                 Statement1
                 statement2
                 
        }
 

Example:

function equal(a,b){

             if(a==b) { alert(“a=b”);}

            else {alert(“a!=b”);}

}



Comments

Name:
Comment:
Enter the text:
CAPTCHA image

Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.