DEV Community

Mohan Mogi
Mohan Mogi

Posted on

Javascript operators

JavaScript operators are special symbols used to perform operations on variables and values. They are the foundation of writing logic in JavaScript programs.

Types of JavaScript types:
1) Arithmetic operators
Arithmetic operators Used to perform mathematical operations.

console.log(a + b);
Addition
console.log(a - b); Subtraction
console.log(a * b); Multiplication
console.log(a / b);
Division
console.log(a % b);
Modulus
console.log(a ** b);
Exponent
2) Assignment Operators
Assignment operators Used to assign values to variables.
x += 5;
x -= 3;
x *= 2;
x /= 2;

3) Comparison Operators
Comparison Operators Used to compare two values and return true or false.

console.log(a == b); true
console.log(a === b); false
console.log(a != b); false
console.log(a > 5); true

4)Logical Operators
Logical Operators Used to combine multiple conditions.

console.log(age > 18 && age < 30);
AND
console.log(age > 18 || age < 10);
OR
console.log(!(age > 18)); NOT

5)Increment and Decrement
Increment and Decrement Used to increase or decrease values.

i++; Increment
i--; Decrement

6)Ternary Operator
Ternary Operator Short form of if-else.
let age = 20;

let result = (age >= 18) ? "Adult" : "Minor";
console.log(result);

7)String Operator
String Operator Used to combine strings.

let first = "Hello";
let second = "World";

console.log(first + " " + second);

8)Type Operator
Type Operator Used to check data type.

Top comments (0)