JavaScript operators are special symbols that perform operations on one or more operands (values),
JavaScript Operator Types:
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- Bitwise Operators(TBD)
- String Operators(TBD)
- Miscellaneous Operators(TBD)
Arithmetic Operators:
- Addition 3 + 4 // 7
- Subtraction 5 - 3 // 2
- Multiplication 2 * 3 // 6 / Division 4 / 2 // 2 % Remainder 5 % 2 // 1 ++ Increment (increments by 1) ++5 or 5++ // 6 (pre and post increments) -- Decrement (decrements by 1) --4 or 4-- // 3 (pre and post decrements) ** Exponentiation (Power) 4 ** 2 // 16
Examples:
let x = 5;
// addition operator
console.log("Addition: x + 3 = ", x + 3);
// subtraction operator
console.log("Subtraction: x - 3 =", x - 3);
// multiplication operator
console.log("Multiplication: x * 3 =", x * 3);
// division operator
console.log("Division: x / 3 =", x / 3);
// remainder operator
console.log("Remainder: x % 3 =", x % 3);
// increment operator
console.log("Increment: ++x =", ++x);
// decrement operator
console.log("Decrement: --x =", --x);
// exponentiation operator
console.log("Exponentiation: x ** 3 =", x ** 3);
same like as --> math.pow(x,3) function
Increment and decrement Operators:
a = 5
++a; // a becomes 6
a++; // a becomes 7
--a; // a becomes 6
a--; // a becomes 5
Adding Strings and Numbers:(Challenges)
Adding two numbers, will return the sum as a number like
console.log( 5 + 5) = 10.
Adding a number and a string, will return the sum as a concatenated string console.log(5 + "5") = "55".
Assignment Operators::
Assignment operators assign values to JavaScript variables.
Given that x = 10 and y = 5, the table below explains the assignment operators:
Comparison Operators:
Comparison operators are used to compare two values.
Comparison operators always return true or false.
Logical Operators:
We use logical operators to perform logical operations on boolean expressions.
References:
https://www.programiz.com/javascript/operators
https://www.w3schools.com/js/js_operators.asp




Top comments (0)