Master AI & Build your First Coding Portfolio with SkillReactor | Sign Up Now

Lesson 2 - Basic JavaScript Syntax

2.3 Basic Operators

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 + 38              
                     -          Subtraction                                              5 - 32              
                     *          Multiplication                                          5 * 315              
                     /          Division                                                15 / 35              
                     %          Modulus (remainder)                                      15 % 43              
Assignment          =          Assigns a value to a variable                            var x = 5;                
                     +=        Adds the right operand to the left and assigns the result to the left operandx += 3;x = x + 3;
                     -=        Subtracts the right operand from the left and assigns the result to the left operandx -= 2;x = x - 2;
                     *=        Multiplies the right operand with the left and assigns the result to the left operandx *= 3;x = x * 3;
                     /=        Divides the left operand by the right and assigns the result to the left operandx /= 2;x = x / 2;
                     %=        Computes the modulus of the two operands and assigns the result to the left operandx %= 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 < 3false          
                     >          Greater than                                            5 > 3true            
                     <=        Less than or equal to                                    5 <= 5true          
                     >=        Greater than or equal to                                5 >= 3true          
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.