Operators and Expressions
This section provides descriptions on operators and expressions, including arithmetic, comparison, logical, bitwise, and assignment operators.
What are expressions? Expressions are sequences of literals, variables, and operators that can be evaluated to values.
1. Arithmetic Operator - Taking numeric values and returning a single numeric value. Arithmetic operators include addition (+), subtraction (-), multiplication (*), and division (/), modulus (%), increment (++), decrement (--), and unary negation (-).
2. Comparison Operator - Taking values of any types and returning a single boolean value. Comparison operators include equal (==), not equal (!=), strict equal (===), strict not equal (!==), greater than (>), greater than or equal (>=), less than (<), and less than or equal (<=).
3. Logical Operator - Taking boolean values and returning a single boolean value. Logical operators include logical AND (&&), logical OR (||), and logical NOT (!).
4. Bitwise Operator - Taking bit strings of 32 bits and returning a single numeric value. Bitwise operators include bitwise AND (&), bitwise OR (|), bitwise XOR (^), bitwise NOT (~), left shift (<<), sign-propagating right shift (>>), and zero-fill right shift (>>>).
5. Assignment Operator - Taking a value of any type and returning a single value. An assignment operator assigns a value to its left operand based on the value of its right operand. Assignment operators include simple assignment (=), assignments combined with arithmetic operators (+=, -=, *=, /=, %=), and assignments combined with bitwise operators (&=, ^=, |=, <<=, >>=, >>>=).
A tutorial example will be given in the next section showing examples of different operators and expressions.
Table of Contents