☜
☞
operator
Sure, here's a more comprehensive list including all the symbols for each type of operator in JavaScript and one example for each:
1. Arithmetic Operators
- Symbols: +, -, *, /, %, ++, --, **
- Examples:
let add = 5 + 3; // 8
let sub = 5 - 3; // 2
let mul = 5 * 3; // 15
let div = 5 / 3; // 1.6666...
let mod = 5 % 3; // 2
let num = 5;
num++; // 6
num--; // 5 again
let exp = 5 ** 3; // 125
2. Assignment Operators
- Symbols: =, +=, -=, *=, /=, %=, **=
- Examples:
let x = 5; // 5
x += 3; // 8
x -= 3; // 5
x *= 3; // 15
x /= 3; // 5
x %= 3; // 2
x **= 3; // 8
3. String Operators
- Symbol: + (there's only one symbol for string operation which is used for concatenation)
- Example:
let text = "Hello" + " " + "World"; // "Hello World"
4. Comparison Operators
- Symbols: ==, ===, !=, !==, >, <, >=, <=
- Examples:
let isEqual = (5 == '5'); // true
let isStrictEqual = (5 === '5'); // false
let isNotEqual = (5 != '5'); // false
let isStrictNotEqual = (5 !== '5'); // true
let isGreater = (5 > 3); // true
let isLesser = (5 < 3); // false
let isGreaterOrEqual = (5 >= 5); // true
let isLesserOrEqual = (5 <= 5); // true
5. Logical Operators
- Symbols: &&, ||, !
- Examples:
let and = (true && false); // false
let or = (true || false); // true
let not = !(true); // false
6. Bitwise Operators
- Symbols: &, |, ^, ~, <<, >>, >>>
- Examples:
let bitwiseAND = (5 & 3); // 1
let bitwiseOR = (5 | 3); // 7
let bitwiseXOR = (5 ^ 3); // 6
let bitwiseNOT = (~5); // -6
let bitwiseLeftShift = (5 << 1); // 10
let bitwiseRightShift = (5 >> 1); // 2
let bitwiseZeroFillRightShift = (5 >>> 1); // 2
7. Conditional (Ternary) Operator
- Symbol: ? :
- Example:
let status = (age >= 18) ? "adult" : "minor"; // "adult" if age is 18 or over, otherwise "minor"
8. Nullish Coalescing Operator
- Symbol: ??
- Example:
let username = userInput ?? "defaultUser"; // "defaultUser" if userInput is null or undefined
This set of examples should give you a comprehensive view of the various operators available in JavaScript, represented by their respective symbols, along with practical usage examples.
☜
☞