JavaScript Operators

This are some of the most commonly used JavaScript operators:

You can conduct a number of operations on various kinds of data using JavaScript's extensive set of operators. The most popular JavaScript functions are listed below:

Arithmetic Operators:

These operators are used to perform mathematical operations like addition, subtraction, multiplication, and division. They include + (addition), - (subtraction), * (multiplication), / (division), % (modulus), ++ (increment), and -- (decrement).

Example:

let a = 5; let b = 2; console.log(a + b); // Output: 7 
console.log(a - b); // Output: 3 
console.log(a * b); // Output: 10 
console.log(a / b); // Output: 2.5 
console.log(a % b); // Output: 1 
console.log(a++); // Output: 5 
console.log(++a); // Output: 7
 console.log(b--); // Output: 2 
console.log(--b); // Output: 0

Assignment Operators:

These operators are used to assign values to variables. They include = (assignment), += (addition assignment), -= (subtraction assignment), *= (multiplication assignment), /= (division assignment), %= (modulus assignment).

Example:

let x = 5; let y = 3; x += y; // Equivalent to x = x + y 
console.log(x); // Output: 8 x %= y; // Equivalent to x = x % y 
console.log(x); // Output: 2

Comparison Operators:

These operators are used to compare two values and return a Boolean value (true or false). They include == (equality), === (strict equality), != (inequality), !== (strict inequality), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or equal to).

Example:

Logical Operators:

These operators are used to perform logical operations on Boolean values. They include && (logical AND), || (logical OR), and ! (logical NOT).

Example:

Bitwise Operators:

These operators are used to perform bitwise operations on integer values. They include & (bitwise AND), | (bitwise OR), ^ (bitwise XOR), ~ (bitwise NOT), << (left shift), and >> (right shift).

Example:

Last updated