DEV Community

Bharath kumar
Bharath kumar

Posted on

Operators in Js

operations:
An operator is a symbol or keyword in programming that performs a specific mathematical or logical operation on one or more values called operands.
types of operators:
Arithmetic Operators:
Perform mathematical calculations.

+ (Addition)  
- (Subtraction) 
* (Multiplication)
/ (Division)
% (Modulus - returns the remainder of a division)
** (Exponentiation)
++ (Increment - increases value by 1)
-- (Decrement - decreases value by 1) 
Enter fullscreen mode Exit fullscreen mode

Assignment Operators:
Assign values to variables.

= (Simple assignment)
+= (Add and assign)
-= (Subtract and assign)
*= (Multiply and assign)
/= (Divide and assign)
%= (Modulus and assign)
**= (Exponentiation and assign) 
Enter fullscreen mode Exit fullscreen mode

Comparison Operators:
Compare two values and return a boolean (true or false) result.

== (Loose equality - compares values after type coercion)
=== (Strict equality - compares values and types)
!= (Loose inequality)
!== (Strict inequality)
> (Greater than)
< (Less than)
>= (Greater than or equal to)
<= (Less than or equal to) 
Enter fullscreen mode Exit fullscreen mode

Logical Operators:
Combine or manipulate boolean values.

&& (Logical AND)
|| (Logical OR)
! (Logical NOT) 
Enter fullscreen mode Exit fullscreen mode

Bitwise Operators:
Perform operations on the binary representation of numbers.

& (Bitwise AND)
| (Bitwise OR)
^ (Bitwise XOR)
~ (Bitwise NOT)
<< (Left shift)
>> (Sign-propagating right shift)
>>> (Zero-fill right shift) 
Enter fullscreen mode Exit fullscreen mode

Ternary (Conditional) Operator:
A shorthand for an if-else statement.

condition ? expressionIfTrue : expressionIfFalse 
Enter fullscreen mode Exit fullscreen mode

Unary Operators:
Operate on a single operand. Examples include typeof, delete, void, + (unary plus), - (unary negation).
String Operators:
Primarily the + operator for string concatenation.
Type Operators:

typeof: Returns the data type of an operand as a string.
instanceof: Checks if an object is an instance of a particular class or constructor function.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)