# Logical AND (&&) Expression

## Summary

Evaluates from left to right. If the first expression evaluates to a falsy value, it is returned; otherwise, the evaluated value of the second expression is returned. This expression can be used to combine conditions in `if` statements and other conditional statements.

## Syntax

`expression1 && expression2`

### Parameters

expression1
Any legal expression.
expression2
Any legal expression.

## Description

`&&` is the logical AND operator. If the first expression evaluates to `false` (or a "falsy" value), it is returned; otherwise, the evaluated value of the second expression is returned. In the case of Boolean expressions, this yields the expected result of `true` if both expressions are `true`, and `false` otherwise. However, with other data types, the output may be non-Boolean. For example, `true && "blue"` yields `"blue"`.

The `&&` operator is evaluated from left to right.

### Using && to test more than one condition in an if statement

The logical AND operator can be used to combine conditions and test if both conditions are true, such as for `if` statements:

 123456 `import` `System;` `bool` `x = ``true``, y = ``true``;``if` `(x && y) {``    ``Console.log(``"'x' and 'y' are both true"``);``}`

### Short-Circuit Evaluation

If the expression prior to an `&&` operator is `false`, then the expression is, if well-formed, `false`. In such cases JS++ does not evaluate the expression following `&&`.

While this "short-circuiting" is logically sound, it means that side effects of the expression after the operator are not executed. For example:

 1234567 `int` `x = 0, y = 0;``if` `((3 < 2) && x++) { ``// does not iterate x because of short-circuiting``    ``y = 1;``}``(3 > 2) && x++; ``// iterates x` `// final result is x = 1 (iterated once) and y = 0`

Care must therefore be taken when the expressions following logical operators are expected to have side effects.