By TechQuest eAcademy · 9/22/2024
In this crash course on JavaScript operators, we will explore what operators are, how they work, and how to use them effectively to manipulate data and perform logical checks. By the end of this video, you will be equipped with the knowledge to use operators in your JavaScript projects. Introduction to Operators
JavaScript operators are symbols that allow you to perform various operations on values, known as operands. The main types of operators we will cover include:
Arithmetic operators allow you to perform calculations:
+
, e.g., let sum = 10 + 5;
results in 15. Addition Example-
, e.g., let difference = 10 - 5;
results in 5. Subtraction Example*
, e.g., let product = 10 * 5;
results in 50. Multiplication Example/
, e.g., let quotient = 10 / 2;
results in 5. Division Example%
. Modulus Example++
to increment and --
to decrement a value. Increment/Decrement ExampleAssignment operators are used to assign values to variables:
=
assigns a value, e.g., let x = 9;
Basic Assignment+=
adds and assigns, e.g., x += 5;
Addition Assignment-=
subtracts and assigns, e.g., y -= 3;
Subtraction Assignment*=
multiplies and assigns, e.g., a *= 5;
Multiplication Assignment/=
divides and assigns, e.g., b /= 3;
Division AssignmentComparison operators compare two values and return true or false:
==
checks for equality, e.g., a == b;
Equal Example===
checks for both value and type equality. Strict Equal Example!=
checks for inequality. Not Equal Example>
checks if one value is greater than another. Greater Than Example<
checks if one value is less than another. Less Than ExampleLogical operators combine multiple conditions:
&&
returns true if both conditions are true. AND Operator Example||
returns true if at least one condition is true. OR Operator ExampleThe ternary operator is a shorthand for if-else statements:
let canVote = (age >= 18) ? 'Yes' : 'No';
``` [Ternary Operator Example](#jumpTo:2406)
## Typeof Operator
The typeof operator checks the type of a value:
```javascript
console.log(typeof 'Hello'); // 'string'
``` [Typeof Operator Example](#jumpTo:2550)
## Conclusion
By understanding these operators, you can effectively manipulate data, perform calculations, and make logical decisions in your JavaScript code. Practice using these operators to become more comfortable with JavaScript programming. [Conclusion and Wrap Up](#jumpTo:2714)
9/24/2024
10/24/2024
10/24/2024
9/30/2024