JavaScript Editor Ajax toolkit     Ajax website 

Main Page

JScript supports if and if...else conditional statements. An if statement tests a condition. It executes the relevant JScript code if the condition evaluates as true. An if...else statement tests a condition and executes one of two blocks of code depending on the result of the condition statement. The simplest form of an if statement can be written on one line, but multiline if and if...else statements are more common.

Conditional Statement Examples

The following examples demonstrate syntaxes you can use with if and if...else statements. The first example shows the simplest kind of Boolean test. If (and only if) the item between the parentheses evaluates to (or can be coerced to) true, the statement or block of statements after the if is executed.

In the following example, the registerUser function is called if the value of newUser converts to true.

В CopyCode imageCopy Code
if (newUser)

In this example, the test fails unless both conditions are true.

В CopyCode imageCopy Code
if (rind.color == "deep yellow " && rind.texture == "wrinkled") {
   theResponse = ("Is it a Crenshaw melon?");

In this example, the code in the body of the do...while loop is executed until the variable quit is true.

В CopyCode imageCopy Code
var quit;
do {
   // ...
   quit = getResponse()
while (!quit)

See Also

JavaScript Editor Ajax toolkit     Ajax website