Loading, please wait...

if…Statement

The if…Statement

If conditional statement is used to execute a block of code if the specified condition is true.

As if the condition is false, then it skips that statement and the further program continues after the closing curly braces and executes the next statements.

 

Syntax

If (condition)
{
  Block of code to be executed if the specified condition is true
}

 

Code:

<html>
<body>
<h2>The If Statement</h2>
<script>
var a = 10;
if(a>5){
document.write("Value of a is greater than 10");
}
</script>
</body>
</html>

Here, as the condition in the “if” statement is true as the value of “a” is greater than 5. So, the block of code which is written inside the “if” statement get executed.

Otherwise, it skips that statement and continues the program execution if the condition is false.

 

Output: