Operators
- JavaScript operators are symbols that are used to perform different operations on values and operands.
Example:
var add=10+10;
Operators in JavaScript.
- Arithmetic Operators
- Comparison (Relational) Operators
- Bitwise Operators
- Logical Operators
- Assignment Operators
- Special Operators
Arithmetic operators:
Example:
var x = 10;
var y = 3;
var sum = x + y; // sum is 13
var product = x * y; // product is 30
Comparison operator:
Example:
var a = 5;
var b = "5";
a == b; // true, loose equality
a === b; // false, strict equality
Bitwise operator:
Example:
var a = 5; // Binary: 0101
var b = 3; // Binary: 0011
var result = a & b; // Bitwise AND: 0001 (Decimal 1)
Logical operator:
Example:
var isTrue = true;
var isFalse = false;
var result = isTrue && isFalse; // result is false
Assignment operator:
Example:
var a = 5;
a += 3; // equivalent to a = a + 3, a is now 8