JavaScript Operators: The Basics You Need to Know

I am a developer learning web development , I am a college dropout pursuing my passion in software field
when we write JS we constantly perform operations on the values, like adding , comparing, making decisions in the condition on the value
Types of operators
In JS we have 4 types of operators
Arithmetic operators :
+,-,*,/,%Comparison operator :
==,===,!=,<,>Assignment operator :
=,+=,-=Logical operator :
&&,||,!
Now we will study each of them in depth starting with aritmetic operator
1. Arithmetic operator
So the most basic operator are Arithmetic operator, these operators perform basic mathss calculation
It has 5 operators under it
Addition:
this will simplity add 2 given valueSubtraction
This will simply subtract 2 given valueMultiplication:
this will simply multiply 2 given valueDivision:
This will simply divide 2 given valueModulo :
This will give us the remainder after dividing the 2 value
2.Comparison operator
Comparison operator compare two valus and return a boolean (true or false) value
Greater than ( > )
Check which value is greater that the otherLess than ( < )
Check which value is smaller than the otherAbstract equality ( loose comparison ) ( == )
This operator compares only the values. It can lead to surprising results because JavaScript will first convert the values to a common type before comparing them. like if we compare number 5 with string 5 then it will give true as it dosen't check data type it only check the final valueStrict equality ( strict comparison ) ( === )
This operator compares both the value AND the type. This is the much safer and more predictable option. If the types are different, it's an immediate 'false'Not equal to ( != )
This operator will check if the given two value are not equal to each other or not, if they are equal then it will give 'false' and if they are not equal then it will return 'true'
And it only return boolean value
3.Assignment operator
we have already been using the most common assignment operator: the equals sign (=). Its job is straightforward: it assigns the value on the right-hand side to the variable on the left.
There are also shorthand assignment operators that let you perform an operation and update the variable's value in a single, clean step. They are a convenient way to make your code more concise.
Assignment operator
It assigns the value in RHS in the LHSAddition Assignment :
Adds and assigns the value in RHS in the LHSSubtract Assignment:
subtract and assigns the value in RHS in the LHSSimmilarly we have multiplication, division, and Modulo Assignment operator
4.Logical operator
Logical operators let you combine two or more Boolean results (true or false) to create complex conditions.
Logical AND ( && )
Returnstrueonly if all of the conditions are true.Logical OR ( || )
Returnstrueif at least one of the conditions is true.Logical NOT ( ! )
Reverses the Boolean value.!truebecomesfalse, and!falsebecomestrue.
Truth Table for Logical Operators




