Operators Flashcards
Operator
Symbol for built-in language calculations
Compound Operators
Provide a shorthand way to update a variable
+=, -=, *=, /=, %=
unary-
Negation of value
-1
%
Modulo
Remainder of the division of two integers
+=
Compound Operator
userAge += 1 IS userAge = userAge + 1
Arithmetic Operators
Perform arithmetic
unary-, *, /, %, +, -
Equality Operators
==, ! =
Cannot be used with floating-point numbers
Logical Operators
Evaluates to true or false (binary)
&&, ||, !
Relational Operators
Evaluates to true or false (binary)
Only one operator is evaluated at a time, based on precedence rules
< , > , <=, >=, ==, !=
Ternary Operator
Conditional expression with 3 operands
Good practice limits use to assignment statements
(condition) ? exprWhenTrue: exprWhenFalse
Short Circuit Evaluation
Logical operators stop left to right evaluation as soon as the result can be determined
AND / OR
++i
Increment Operator
Shorthand of i = i + 1
–i
Decrement Operator
Shortand of i = i - 1
[]
String position