JavaScript Operators
JS
JavaScript operators are symbols or keywords used to perform operations on variables and values.
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- Conditional (Ternary) Operator
- Type Operators
1. Arithmetic Operators
Arithmetic operators in JavaScript are used to perform basic mathematical operations, such as addition, subtraction, multiplication, and more.
A. Addition (+)
B. Subtraction(-)
C. Multiplication (*)
D. Division (/)
E. Modulus (%)
F. Increment (++)
Pre-increment: a is incremented before it is assigned to b
Post-increment: a is incremented after it is assigned to b
G. Decresument (--)
Pre-decrement: a is decremented before it is assigned to b
Post-decrement: a is decremented after it is assigned to b
2. Assignment Operators
Assignment operators are symbols used in programming to assign values to variables.
= Assign
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign
%= Modulus and assign
3. Comparison Operators
Comparison operators in JavaScript are used to compare two values and return true or false.
==
Is equal to
===
Identical (equal and of same type)
!=
Not equal to
!==
Not Identical
>
Greater than
>=
Greater than or equal to
<
Less than
<=
Less than or equal to
4. Logical (relational) Operators
Logical (Relational) Operators are used in programming to compare two values or expressions and determine the relationship between them. These operators return boolean values: True or False.
&&
Logical AND
||
Logical OR
!
Logical Not
5. Conditional (ternary) Operators
Conditional (Ternary) Operators allow you to evaluate a condition in a concise, single-line format. These operators are used to decide which value or expression to return based on a given condition. They are essentially shorthand for an if-else statement.
? :
Conditional
condition ? value if true : value if false
6. Type Operator
Type operators are used in programming to determine or manipulate the type of a variable.
Returns the type of a variable