Web Development: Javascript Control Structures
Posted on April 21st, 2009
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.
Posted in Development | | | Digg This | del.icio.us | Technorati
Related Topics:
Web Development: Javascript Frameworks
Web Development: Introduction to Javascript
Everything PHP: Alternative Syntax for Control Structures
Web Development: Beginning Javascript
Web Development: Document Object Model
2 Comments
Sorry, the comment form is closed at this time.
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.
I hardly think a simple typo is a “serious” syntax error. As for the comment placement, also a typo. Both have been corrected.