Learn JavaScript
Lesson 1 - Introduction To JavaScript
Lesson 3 - Control Flow
Lesson 4 - Functions
Lesson 5 - Basic Data Structures
Lesson 6 - Basic String Operations
Lesson 7 - Basic Array Operations
Lesson 8 - Exception Handling
Lesson 9 - Packages
Lesson 10 - User Input
Before we get into deeper to JavaScript, it's crucial to be familiar with the basic operators used in JavaScript coding.
The following chart introduces operators under different categories,
Category | Operator | Description | Example |
---|---|---|---|
Arithmetic | + | Addition | 5 + 3 → 8 |
- | Subtraction | 5 - 3 → 2 | |
* | Multiplication | 5 * 3 → 15 | |
/ | Division | 15 / 3 → 5 | |
% | Modulus (remainder) | 15 % 4 → 3 | |
Assignment | = | Assigns a value to a variable | var x = 5; |
+= | Adds the right operand to the left and assigns the result to the left operand | x += 3; → x = x + 3; | |
-= | Subtracts the right operand from the left and assigns the result to the left operand | x -= 2; → x = x - 2; | |
*= | Multiplies the right operand with the left and assigns the result to the left operand | x *= 3; → x = x * 3; | |
/= | Divides the left operand by the right and assigns the result to the left operand | x /= 2; → x = x / 2; | |
%= | Computes the modulus of the two operands and assigns the result to the left operand | x %= 3; → x = x % 3; | |
Comparison | == | Equality (loose equality) | 5 == '5' → true |
=== | Strict equality (checks both value and type) | 5 === '5' → false | |
!= | Inequality (loose inequality) | 5 != '5' → false | |
!== | Strict inequality (checks both value and type) | 5 !== '5' → true | |
< | Less than | 5 < 3 → false | |
> | Greater than | 5 > 3 → true | |
<= | Less than or equal to | 5 <= 5 → true | |
>= | Greater than or equal to | 5 >= 3 → true | |
Logical | && | Logical AND | (x < 10) && (y > 5) |
|| | Logical OR | (x == 5) || (y == 5) | |
! | Logical NOT | !(x == y) |
These operators are essential for performing various operations and logic in JavaScript programming.
Now, we have a detailed list of basic operators in JavaScript. Let's see how we can use them,
let x = 8 let y = 3 if (x < 10 && y > 5) console.log("True") else console.log("False")
In the example above, we used the logical AND
operator inside the conditional statement. We discussed conditional statements in great detail later in this lesson.