Conditionally executes a group of statements, depending on the value of an expression.
In the following example, you may intend that the else be used with the first if statement, but it is used with the second one.
The above example is equivalent to the following code:
Changing the code in the following manner eliminates any ambiguities:
Similarly, if you want to add a statement to statement1, and you do not use braces, you can accidentally create an error:
In this case, there is a syntax error, because there is more than one statement between the if and else statements. Braces are required around the statements between if and else.
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.