JavaScript Resources

Logical Operators

Logical operators can be used to expand the number of conditions that can be used to evaluate an expression.

The || symbols allow you to direct that any one of a set of expressions can evaluate to true in order for the conditional statement to execute. This is also known as logical OR.

For example:

    if (userName == "Scooby" || userName == "Shaggy") {

      alert(userName + "! There is a Scooby snack waiting for you somewhere in this website!")

    }

The symbol | used for this operator is called the pipe symbol, and it is usually located above the ENTER key on your keyboard.

The && symbols allow you to direct that two or more expressions must all evaluate to true in order for the conditional statement to execute. This is also known as logical AND.

For example:

    if (navigator.appName == "Netscape" && parseInt(navigator.appVersion) == 4) {

      alert("Wow! You are using a really old web browser. Time for an upgrage!")

    }

That's decision making in a nutshell. This should be enough to get you started.

Finally... take a look next at some decision making examples