
Javascript may just be a client-side scripting language, but it still contains the essence of more powerful, server-side languages. Javascript contains control structures, such as if/else if/else statements and for loops.
Since Javascript is a much more powerful language than just manipulating the Document Object Model, possibilities with it become almost endless. Take Adobe Flash for example, its powerful scripting language (ActionScript) is based on the same standard as Javascript is. Another example: you can even use Javascript to create desktop applications with Adobe AIR.
We’re going to look at the if/else if/else statements today. The if statement allows you to check if a certain condition evaluates to true. The else if statement will check another condition if the previous one is false. The else statement will be evaluated if all the preceding if and else if statements are false. Let’s take a look at the syntax of these statements:
[code='javascript']if (condition_1)
{
// If this condition is true, the code inside this block will be executed
}
else if (condition_2)
{ // If the previous if condition is false, this will be evaluated
// If this condition is true, this block will be executed
}
else {
// If none of the preceding conditions are true, this block will be executed
}[/code]
As you can see, control structures such as if/else if/else statements allow you to use Javascript in a more advanced manner.





Scott D. Sullivan-Reinhart
April 21, 2009 12:57 am
This is all well and good but a few points to make…
1) This is less powerful than DOM manipulation
2) You have a serious syntax error in your example
3) You have a serious error in your placement of comments which once again is a syntax error
If you want more information email me.
Matt Freedman
April 22, 2009 1:14 pm
I hardly think a simple typo is a “serious” syntax error. As for the comment placement, also a typo. Both have been corrected.