# JavaScript Operators

Types of Operators in JavaScript’s –This chapter describes JavaScript’s expressions and operators, including assignment, comparison, arithmetic, bitwise, logical, string, ternary and more.

## Types of Operators in JavaScript’s

• Assignment operators
• Comparison operators
• Arithmetic operators
• Bitwise operators
• Logical operators
• String operators
• Conditional (ternary) operator
• Comma operator
• Unary operators
• Relational operators

JavaScript has both binary and unary operators, and one special ternary operator, the conditional operator. A binary operator requires two operands, one before the operator and one after the operator:

``````
4 + 2
X * Y
```
```

A unary operator requires a single operand, either before or after the operator:

``````
X++
++X
```
```

## JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.

## JavaScript Comparison Operators

Comparison operators are used in logical statements to determine equality or difference between variables or values.

## JavaScript Arithmetic Operators

Arithmetic operators perform arithmetic on numbers (literals or variables).

``````
let x = 100 + 50;
let x = a + b;
```
```

## JavaScript Bitwise Operators

Bit operators work on 32 bits numbers.

Any numeric operand in the operation is converted into a 32 bit number. The result is converted back to a JavaScript number.

The following table summarizes JavaScript’s bitwise operators.

## JavaScript Logical Operators

Logical operators are used to determine the logic between variables or values.

Logical operators are typically used with Boolean (logical) values; when they are, they return a Boolean value. However, the `&&` and `||` operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value.

## JavaScript String Operators

In addition to the comparison operators, which can be used on string values, the concatenation operator `(+)` concatenates two string values together, returning another string that is the union of the two operand strings.

``````
console.log('my ' + 'string'); // console logs the string "my string".
```
```

The shorthand assignment operator `+=` can also be used to concatenate strings.

``````
var mystring = 'alpha';
mystring += 'bet'; // evaluates to "alphabet" and assigns this value to mystring.
```
```

## JavaScript Conditional (ternary) Operator

The conditional operator is the only JavaScript operator that takes three operands. The operator can have one of two values based on a condition.

### Syntax :

``````
variablename = (condition) ? value1:value2
```
```

### Example :

``````
let voteable = (age < 18) ? "Too young" : "Old enough";
```
```

If the variable age is a value below 18, the value of the variable voteable will be “Too young”, otherwise the value of voteable will be “Old enough”.

## JavaScript Unary operators

Unary operators work on one value.

I hope you like this Types of Operators in JavaScript’s article.