Have you thought about how we can tell our program to do a specific task? For example, how do we add two numbers together or compare two values?

## What are operators and operands?

- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical Operators
- Ternary Operators
- typeof Operator

## Arithmetic Operators

Operator Name | Operator symbol | Description | Example |
---|---|---|---|

let x = 10, y = 5 | |||

Addition | + | Adds two numeric operands. | x + y = 15 |

Subtraction | - | Subtract right operand from left operand. | x - y = 5 |

Multiplication | * | Multiply two numeric operands. | x * y = 50 |

Division | / | Divide left operand by right operand. | x / y = 2 |

Remainder | % | Returns remainder of two operands. | x % y = 0 |

Increment | ++ | Increase operand value by one. | ++x = 11 |

Decrement | -- | Decrease value by one. | y-- = 5 |

Exponentiation | ** | Raise one operand to the power of the other operand. | x ** y = 100000 |

let x = 10; let y = 5; let z = 3; console.log(x + y); // 10 + 5 --> 15 console.log(x - y); // 10 - 5 --> 5 console.log(x * y); // 10 * 5 --> 50 console.log(x / y); // 10 / 5 --> 2 console.log(x % z); // 10 % 3 --> 1 console.log(x++); // 10 console.log(--y); // 4 console.log(y ** y); // 5 * 5 * 5 --> 125

### JavaScript prefix and postfix

// Increment let x = 2; console.log(x++); // 2 console.log(x); // 3 // Decrement let y = 5; console.log(y--); // 5 console.log(y); // 4

// Increment let x = 2; console.log(++x); // 3 console.log(x); // 3 // Decrement let y = 5; console.log(--y); // 4 console.log(y); // 4

### Using the + operator to concatenate strings

const firstName = 'John'; const lastName = 'Smith'; console.log(firstName + lastName); // JohnSmith

//Space after the first name const firstName = 'John '; const lastName = 'Smith'; console.log(firstName + lastName); // John Smith //Space before the last name const firstName = 'John'; const lastName = ' Smith'; console.log(firstName + lastName); // John Smith //Add empty string in between variables const firstName = 'John'; const lastName = 'Smith'; console.log(firstName + ' ' + lastName); // John Smith

## Assignment Operators

Operator Name | Symbol | Description | Longform version | Example |
---|---|---|---|---|

let x = 5, />y = 10 | ||||

Assignment | x = y | Assigns right operand value to the left operand. | x = 10; | |

Addition | x += y | Sums up left and right operand values and assigns the result to the left operand. | x = x + y | x += 10; |

Subtraction | x -= y | Subtract right operand value from the left operand value and assigns the result to the left operand. | x = x - y | x -= 10; |

Multiplication | x *= y | Multiply left and right operand values and assigns the result to the left operand. | x = x * y | x *= 10; |

Division | x /= y | Divide left operand value by right operand value and assign the result to the left operand. | x = x / y | x /= 10; |

Remainder | x %= y | Get the remainder of left operand divide by right operand and assign resulted remainder to the left operand. | x = x % y | x %= 10; |

## Operator Precedence

console.log(5 + 3 - 2); // 6 console.log(5 - 4 + 3); // 4

- Comparison Operators
- Logical Operators
- Ternary Operators
- typeof Operator