January 2003
Beginner to intermediate
1200 pages
23h 42m
English
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 ...