When diving into JavaScript, you'll inevitably come across operators. They're the building blocks of your code, enabling you to perform actions or computations with values. In this tutorial, we'll explore the various types of JavaScript operators, their functions, and how to use them effectively.

JavaScript supports several types of operators, each serving a unique purpose. Let's break down these operators into categories and dig deeper into each.

Arithmetic Operators
Arithmetic operators are used to perform mathematical operations. They include addition (+), subtraction (-), multiplication (*), division (/), and modulus (%). Let's explore these with examples.

Here's a basic example of each:
| Operator | Example | Result |
|---|---|---|
| + | var a = 10; var b = 5; var c = a + b; | c = 15 |
| - | var a = 10; var b = 5; var c = a - b; | c = 5 |
| * | var a = 10; var b = 5; var c = a * b; | c = 50 |
| / | var a = 10; var b = 5; var c = a / b; | c = 2 |
| % | var a = 10; var b = 3; var c = a % b; | c = 1 (remainder of 10 divided by 3) |

Infix and Postfix Operators
JavaScript also supports infix and postfix operators for increment (++) and decrement (--). Here's how they work:
Infix: var a = 10; a++; (a now equals 11)

Postfix: var a = 10; var b = a++; (b equals 10, a now equals 11)
Assignment Operators
Assignment operators assign values to variables. The basic assignment operator is =, but JavaScript also offers shorthand operators like +=, -=, *=, /=, and %=, which perform an operation and assign the result to the variable in one step.

For example, var a = 10; a += 5; makes a equal to 15.
AND, OR, and NOT Operators




















Logic operators perform logical operations on boolean values (true or false). The AND operator (&&) returns true if both operands are true. The OR operator (||) returns true if either operand is true. The NOT operator (!) negates its operand.
var a = true; var b = false; var c = a && b; (c equals false), var d = a || b; (d equals true), var e = !a; (e equals false)
Comparison Operators
Comparison operators compare two values and return a boolean value (true or false). They are crucial for decision-making in your code.
Here they are: == (equal), != (not equal), === (strictly equal), !== (strictly not equal), > (greater than), < (less than), >= (greater than or equal), and <= (less than or equal).
Equality and Inequality Operators
The equality (==) and inequality (!=) operators compare values, while the strictly equal (===) and strictly not equal (!==) operators compare both values and types.
var a = 10; var b = "10"; var c = a == b; (c equals true), var d = a === b; (d equals false)
Ternary Operator
The ternary operator is a shorthand way of writing an if-else statement. It consists of three operands: a condition, a value to return if the condition is true, and a value to return if the condition is false.
var a = 10; var b = (a > 5) ? "greater than 5" : "less than or equal to 5";
JavaScript operators are powerful tools for manipulating data and making decisions in your code. Practice using them in various scenarios to become proficient. Now that you've learned about the different types of operators, you're ready to apply this knowledge to your JavaScript projects.