JS If Statement

JavaScript If-else

The JavaScript if-else statement is used to execute the code whether condition is true or false. There are three forms of if statement in JavaScript.

  1. If Statement
  2. If else statement
  3. if else if statement

JavaScript If statement

It evaluates the content only if expression is true. The signature of JavaScript if statement is given below.

if(expression){  
   //content to be evaluated  
}




<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>JavaScript</title>
    <script>
         /* Greater Than If Condition */
        var a = 100;
        var b = 20;

        if(a > b) {
            document.write("A is Greater");
        }
		document.write("<br><br>");

        /* Equal to If Condition */
        var m = 100;
        var n = 100;

        if (m == n) {
            document.write("A is Greater");
        }
		document.write("<br><br>");

        /* Equal value and equal type If Condition */
        var x = 100;
        var y = "100";
        if (x === y) {
            document.write("Yahoo Baba");
        }
		document.write("<br><br>");
    </script>
</head>
<body>
</body>
</html>