Operators in Java Script
In JavaScript, operators are special symbols used to perform operations on values and variables. The values being acted upon are called operands.
For example, in
10 + 5, the + is the operator and 10 and 5 are the operands.Types of Operators in Java Script:
1. Arithmetic Operators
Used to perform standard mathematical calculations.
+(Addition):5 + 2 // 7-(Subtraction):5 - 2 // 3*(Multiplication):5 * 2 // 10/(Division):10 / 2 // 5%(Modulus/Remainder):10 % 3 // 1**(Exponentiation):2 ** 3 // 8
2. Assignment Operators
Used to assign values to variables.
=: Simple assignment (x = 10)+=: Addition assignment (x += 5is the same asx = x + 5)-=,*=,/=: Perform the math and assign the result.
3. Comparison Operators
Used to compare two values and return a Boolean (
true or false).==: Equal to (checks value only).===: Strict equal (checks both value and data type—highly recommended).!=: Not equal to.>/<: Greater than / Less than.>=/<=: Greater than or equal / Less than or equal.
4. Logical Operators
Used to determine logic between variables or values.
&&(Logical AND): Returnstrueif both statements are true.||(Logical OR): Returnstrueif at least one statement is true.!(Logical NOT): Reverses the result (true becomes false).
5. The Ternary Operator
A shorthand for an
if-else statement.- Syntax:
condition ? valueIfTrue : valueIfFalse - Example:
let status = (age >= 18) ? "Adult" : "Minor";