Contents

## What is an Operator?

An operator is a special symbol in JavaScript that is used to perform operations on operands (values and variables). For example:

Here, operator + performs addition, and 4 and 5 are operands.

## JavaScript Operator Types

The following is a list of the various operators that we will learn in this tutorial.

• Assignment Operators
• Arithmetic Operators
• Comparison Operators
• Logical Operators
• Bitwise Operators
• String Operators
• Other Operators

### Assignment Operators in JavaScript

Variables are assigned values using the assignment operators. For example:

The = operator is used to assign the value 5 to variable x in this case.

Here’s a list of the most common assignment operators:

Note: The assignment operator = is commonly used. Once you’ve learned arithmetic operators, you’ll be able to understand other assignment operators like +=, -=, *=, and so on.

### Arithmetic Operators in JavaScript

To perform arithmetic calculations, arithmetic operators are used. For example:

The + operator is used to combine two operands in this case.

Here’s a list of the most common arithmetic operators:

Example of Arithmetic Operators:

```let x = 8;
let y = 4;

console.log('x + y = ', x + y);  // 12

// subtraction
console.log('x - y = ', x - y);  // 4

// multiplication
console.log('x * y = ', x * y);  // 32

// division
console.log('x / y = ', x / y);  // 2

// remainder
console.log('x % y = ', x % y);   // 2

// increment
console.log('++x = ', ++x); // x is now 9
console.log('x++ = ', x++); // prints 9 and then increased to 10
console.log('x = ', x);     // 10

// decrement
console.log('--x = ', --x); // x is now 9
console.log('x-- = ', x--); // prints 9 and then decreased to 8
console.log('x = ', x);     // 8

//exponentiation
console.log('x ** y =', x ** y);```

Note: the ** operator was introduced in ECMAScript 2016 and may not be supported by all browsers.

### Comparison Operators in JavaScript

Comparison operators compare two values and return either true or false as a boolean value. For example:

The comparison operator > is used to see if x is greater than y in this case.

Here’s a list of the most common comparison operators:

Example of Comparison Operators:

```// equal operator
console.log(7 == 7); // true
console.log(7 == '7'); // true

// not equal operator
console.log(7 != 5); // true
console.log('hello' != 'Hello'); // true

// strict equal operator
console.log(7 === 7); // true
console.log(7 === '7'); // false

// strict not equal operator
console.log(7 !== '7'); // true
console.log(7 !== 7); // false
```

### Logical Operators in JavaScript

Logical operators carry out logical operations and return a true or false boolean value. For example:

The logical operator AND(&&) is used here. The result is true because both x < 9 and y < 6 are true.

Here’s a list of the most common logical operators:

Example of Logical Operators:

```// logical AND
console.log(true && true); // true
console.log(true && false); // false

// logical OR
console.log(true || false); // true

// logical NOT
console.log(!true); // false
```

### Bitwise Operators in JavaScript

Operations on binary representations of numbers are performed by bitwise operators.

Here’s a list of the most common bitwise operators:

### String Operators in JavaScript

You can also use the + operator in JavaScript to concatenate (join) two or more strings.

Example of String Operators:

```// concatenation operator
console.log('Developers' + 'dome');   //  Developersdome

let a = 'JavaScript';

a += ' tutorial';  // a = a + ' tutorial';   //   JavaScript tutorial
console.log(a);```

Note: The + concatenates(joins) strings when used with them. However, when + is used with numbers, it performs addition.

### Other JavaScript Operators

The following is a list of other JavaScript operators:

That’s all about the Operators in JavaScript.

You may like Datatypes in JavaScript.

Hope this article will guide you to recognize the Operators in JavaScript that you needed and still if you have any problems or queries regarding this, post them in the comments section and we will be glad to assist you.