JavaScript (Operators) Flashcards
(22 cards)
JavaScript provides several ____ that
allow you to perform basic mathematical operations.
These are similar to operators found in other
programming languages and calculators
arithmetic operators
Adds two numbers.
Also used for string concatenation
Example: 10 + 3 = 13
Addition (+)
Subtracts the second number from the first.
Example: 10 - 3 =
Subtraction (-)
Multiplies two numbers.
Example: 10 * 3 = 30
Multiplication (*)
Divides the first number by the second.
The result can be a floating-point number.
Example: 10 / 3 = 3.3333
Division (/)
Returns the remainder of a division.
Often used to determine if a number is even or odd.
Example: 10 % 3 = 1
Modulo (%)
Raises the first number to the power of the second number.
Equivalent to Math.pow(a, b).
Example: 10 ** 3 = 1000
Exponentiation (**)
allow developers to
compare values. These comparisons return a Boolean
(true or false) and are fundamental for making decisions
in code.
Comparison
Types of Comparison
Operators
- Equality
- Inequality
- Relational Comparison
- Comparison in Conditional Statements
Compares values but ignores
type differences.
console.log(5 == “5”); // true
Loose Equality (==
)
Compares both value and
type
console.log(5 === “5”); // false
Strict Equality (===
)
Checks if values are
different, ignoring type.
console.log(5 != “5”); // false
Loose Inequality (!=
)
Checks if values and types
are different.
console.log(5 !== “5”); // true
Strict Inequality (!==
)
Relational Comparison Operators
- Greater than (
>
) - Less than (
<
) - Greater than or equal to (
>=
) - Less than or equal to (
<=
)
help evaluate conditions that involve
multiple Boolean expressions. They return either true
or false
depending on how the conditions interact.
Logical operators
Types of Logical
Operators
AND (&&
)
OR (||
)
Returns true
if both conditions are true
AND (&&
)
Returns true
if at least one condition is true
OR (||
)
Reverses the Boolean value
NOT (!
)
Logical operators evaluate expressions from left to right,
sometimes stopping early
TRUE OR FALSE
TRUE
is a shorthand
way to write an if-else statement. It evaluates a
condition and returns one of two values based on
whether the condition is true or false
Ternary Operator
Operators with
higher
precedence
execute before
lower-precedence
ones.
TRUE OR FALASE
TRUE