Statements and Operators

if()

if() statements allow for conditional execution of code. For example, given a variable cust_number:

if (cust_number == 2){
       Response.Write("Hello Jim")    // prints "Hello
                                      // Jim" in browser
}

This would be useful if we knew that Jim was customer number two. We might also want to welcome other customers, which we could do with an else clause to handle other values:

if (cust_number == 2){
       Response.Write("Hello Jim");
}
else{
       Response.Write("Welcome to our web site");
}

Besides the equality operator above (two equal signs, rather than the single equal sign used to assign a value to a variable), JavaScript supports the usual other operators as shown in Table A-1.

Table A-1. More Operators!
Operator Definition
!= Not ...

Get Essential ASP for Web Professionals now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.