Operators and Expressions
Operators in JavaScript allow you to perform operations on variables and
values, creating expressions that produce new values.
Arithmetic Operators
Used to perform basic math operations:
Operator |
Description |
Example |
Result |
|
Addition |
|
|
|
Subtraction |
|
|
|
Multiplication |
|
|
|
Division |
|
|
|
Modulus (remainder) |
|
|
|
Increment |
|
|
|
Decrement |
|
|
Assignment Operators
Used to assign values to variables, often
combined with arithmetic:
Operator |
Description |
Example |
Result |
|
Assign |
|
|
|
Add and assign |
|
|
|
Subtract and assign |
|
|
|
Multiply and assign |
|
|
|
Divide and assign |
|
|
|
Modulus and assign |
|
|
Comparison Operators
Compare values and return a Boolean (true
or false
):
Operator |
Description |
Example |
Result |
|
Equal (value only) |
|
|
|
Equal (value and type) |
|
|
|
Not equal (value only) |
|
|
|
Not equal (value/type) |
|
|
|
Less than |
|
|
|
Greater than |
|
|
|
Less than or equal |
|
|
|
Greater than or equal |
|
|
Logical Operators
Used to combine or invert Boolean values:
Operator |
Description |
Example |
Result |
|
Logical AND |
|
|
` |
` |
Logical OR |
|
|
Logical NOT |
|
|
String Concatenation
The +
operator can also join (concatenate)
strings:
let greeting =
"Hello, " +
"world!";
console.
log(greeting);
// Output: Hello, world!
You can also combine variables and strings:
let name =
"Alice";
console.
log(
"Hi, " + name +
"!");
// Output: Hi, Alice!