#6 JavaScript Operators ( Arithmetic, Comparison, Logical)

preview_player
Показать описание
Certainly! Let's discuss arithmetic, comparison, and logical operators in JavaScript.

### Arithmetic Operators:

1. **Addition (`+`):**
- Adds two values together.
- Example: `let sum = 3 + 5;` (The value of `sum` will be 8.)

2. **Subtraction (`-`):**
- Subtracts the right operand from the left operand.
- Example: `let difference = 8 - 3;` (The value of `difference` will be 5.)

3. **Multiplication (`*`):**
- Multiplies two values.
- Example: `let product = 4 * 6;` (The value of `product` will be 24.)

4. **Division (`/`):**
- Divides the left operand by the right operand.
- Example: `let quotient = 10 / 2;` (The value of `quotient` will be 5.)

5. **Modulus (`%`):**
- Returns the remainder of the division of the left operand by the right operand.
- Example: `let remainder = 7 % 3;` (The value of `remainder` will be 1.)

6. **Exponentiation (`**`):**
- Raises the left operand to the power of the right operand.
- Example: `let result = 2 ** 3;` (The value of `result` will be 8.)

### Comparison Operators:

1. **Equal (`==`):**
- Checks if two values are equal, performing type coercion if necessary.
- Example: `let isEqual = 5 == '5';` (The value of `isEqual` will be `true` due to type coercion.)

2. **Strict Equal (`===`):**
- Checks if two values are equal without type coercion (strict equality).
- Example: `let isStrictEqual = 5 === '5';` (The value of `isStrictEqual` will be `false` due to different types.)

3. **Not Equal (`!=`):**
- Checks if two values are not equal, performing type coercion if necessary.
- Example: `let isNotEqual = 5 != '5';` (The value of `isNotEqual` will be `false` due to type coercion.)

4. **Strict Not Equal (`!==`):**
- Checks if two values are not equal without type coercion (strict inequality).
- Example: `let isStrictNotEqual = 5 !== '5';` (The value of `isStrictNotEqual` will be `true` due to different types.)

5. **Greater Than :**
- Checks if the left operand is greater than the right operand.

6. **Less Than :**
- Checks if the left operand is less than the right operand.

7. **Greater Than or Equal To:**
- Checks if the left operand is greater than or equal to the right operand.

8. **Less Than or Equal To:**
- Checks if the left operand is less than or equal to the right operand.

### Logical Operators:

1. **Logical AND (`&&`):**
- Returns `true` if both operands are `true`.

2. **Logical OR (`||`):**
- Returns `true` if at least one of the operands is `true`.

3. **Logical NOT (`!`):**
- Returns `true` if the operand is `false`, and vice versa.

These operators are fundamental in JavaScript and are used extensively for performing various operations, making decisions, and controlling the flow of programs.
Рекомендации по теме
welcome to shbcf.ru