Skip to the content.

Operators and Loops

Return to Home

Expressions and Operators

Expressions and operators

At a high level, an expression is a valid unit of code that resolves to a value. There are two types of expressions: those that have side effects (such as assigning values) and those that purely evaluate.

Assignment operators

An assignment operator assigns a value to its left operand based on the value of its right operand. The simple assignment operator is equal (=), which assigns the value of its right operand to its left operand.

Assigning to properties

If an expression evaluates to an object, then the left-hand side of an assignment expression may make assignments to properties of that expression.

Comparison operators

A comparison operator compares its operands and returns a logical value based on whether the comparison is true. The operands can be numerical, string, logical, or object values.

Loops and iteration

Loops offer a quick and easy way to do something repeatedly. All repeat an action a number of times, could be 0.

For statement

A for loop repeats until a specified condition evaluates to false.

While statement

A while statement executes its statements as long as a specified condition evaluates to true. Avoid infinite loops. Make sure the condition in a loop eventually becomes false—otherwise, the loop will never terminate.