Skip to Content
Real World XML
book

Real World XML

by Steven Holzner
January 2003
Beginner to intermediate content levelBeginner to intermediate
1200 pages
23h 42m
English
Peachpit Press
Content preview from Real World XML

Creating JavaScript if Statements

You use the if statement in JavaScript to test your data and to execute some code if the test is true. Here's the basic form of the if statement:

if (condition) {
    code
}

Here, condition is the test that you want to make, and code is the code you want to execute if the condition is true. One thing to note here is that you must enclose the code to execute in curly braces, { and }.

So what kind of conditions can you check, and how do you do so? To construct a condition to test, you use the comparison operators, such as < (less than), > (greater than), == (is equal to), <= (is less than or equal to), or >= (is greater than or equal to).

Here's an example. in this case, I'm making sure that the value in a variable ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Inside XML

Inside XML

Steven Holzner
XML Hacks

XML Hacks

Michael Fitzgerald

Publisher Resources

ISBN: 0735712867Purchase book