Expressions
Last updated
Last updated
Expressions are utilized to assign values to variables. An expression typically consists of variables, constants, operators, and functions, arranged in a specific order to perform a computation or evaluation. These expressions can range from simple assignments to complex calculations, facilitating various operations within the programming environment.
.
- Dot operator used to access attributes and methods
[]
- Square operator used to access elements of arrays
()
- Parentheses, also known as round brackets or simply brackets, are punctuation marks used in 3 purposes.
Grouping and Clarity: Parentheses are used to group elements within a expression to indicate a specific order of operations or to enhance readability. They help clarify the structure and meaning of a sentence by enclosing supplementary information or clarifications.
Example:
I enjoy eating (especially chocolate) when I'm stressed.
(x + y) * (x - y)
(to indicate that addition comes before subtraction)
Mathematical Expressions: In mathematical expressions, parentheses are used to indicate precedence or to specify the order of operations. Operations within parentheses are performed before those outside of parentheses.
Example:
(3 + 5) * 2
is evaluated differently than 3 + (5 * 2)
Function Calls: parentheses are used to denote function calls. When calling a function, the arguments (if any) are placed within the parentheses.
Example:
Math.pow(2, 4)
(calling the pow
function with the arguments 2 and 4)
+
-
*
/
- math operators
=
<
>
<=
>=
!=
- numbers comparison operators
and
or
not
- boolean operators
List of available variables depends on scope (node position). Variables can be:
See Expression functions page for more details.