Updated on Kisan Patel
In javascript, If statement is used to execute a block of statements only when certain condition is met.
The syntax of if is
if (condition) statement if the condition is true
Example
var a, b; a = 10; b = 20; if (a < b) { document.write("<h3>b is largest number</h3>"); }
See the Pen oXOeOx by Kisan (@pka246) on CodePen.
We can use various operators such as arithmetic operator, logical operator, relational operators and so on in the if statement.
See the Pen bdJryv by Kisan (@pka246) on CodePen.