Skip to content

Commit 7223eb1

Browse files
committed
Added operators
1 parent 690ea7b commit 7223eb1

File tree

2 files changed

+132
-6
lines changed

2 files changed

+132
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ This repository contains Vanilla JavaScript topics and their notes to learn from
3131
- [Arrays](./docs/data-types.md#-arrays)
3232
- [Objects](./docs/data-types.md#-objects)
3333
- [comparison](./docs/data-types.md#-comparison)
34-
- Operators
35-
- Arithmetic
36-
- Comparison
37-
- Logical
38-
- Assignment
39-
- Ternary
34+
- [Operators](./docs/operators.md)
35+
- [Arithmetic](./docs/operators.md#-arithmetic)
36+
- [Comparison ](./docs/operators.md#-comparison)
37+
- [Logical ](./docs/operators.md#-logical)
38+
- [Assignment](./docs/operators.md#-assignment)
39+
- [Ternary](./docs/operators.md#-ternary)
4040
- Control flow
4141
- Conditional statements
4242
- Loops

docs/operators.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
## ⚑ Operators
2+
Operators are represented by symbols or keywords that perform specific operations on values in JavaScript. They are used to manipulate data, create expressions, and control the flow of your code.
3+
4+
*There are 5 common operators in JavaScript.*
5+
6+
### ☴ Overview:
7+
1. [Arithmetic](#-arithmetic)
8+
2. [Comparison](#-comparison)
9+
3. [Logical](#-logical)
10+
4. [Assignment](#-assignment)
11+
5. [Ternary](#-ternary)
12+
13+
### ✦ Arithmetic:
14+
Arithmetic operators is used to perform mathematical operations such as addition, subtraction, multiplication, division, modulo, increment, decrement.
15+
16+
*Syntax:*
17+
```javascript
18+
+ (addition)
19+
- (subtraction)
20+
* (multiplication)
21+
/ (division)
22+
% (modulo)
23+
++ (increment)
24+
-- (decrement)
25+
```
26+
27+
```javascript
28+
let addition = 5 + 3; // 8
29+
let subtraction = 5 - 3; // 2
30+
let multiplication = 5 * 3; // 15
31+
let division = 5 / 3; // 1
32+
let remainder = 5 % 3; // 2
33+
++addition; // pre-increment
34+
addition++; // post-increment
35+
--addition; // pre-decrement
36+
addition--; // post-decrement
37+
```
38+
39+
### ✦ Comparison:
40+
Comparison operators is used to compare values and return a boolean result. comparison between values done such as equal to, not equal to, strictly equal to, strictly not equal to, greater than, less than, greater than or equal to, less than or equal to.
41+
42+
*Syntax:*
43+
```javascript
44+
== (equal to)
45+
!= (not equal to)
46+
=== (strictly equal to)
47+
!== (strictly not equal to)
48+
> (greater than)
49+
< (less than)
50+
>= (greater than or equal to)
51+
<= (less than or equal to)
52+
```
53+
54+
```javascript
55+
let x = 10;
56+
let y = 5;
57+
58+
if (x > y) {
59+
console.log("x is greater than y");
60+
}
61+
```
62+
63+
### &#10022; Logical:
64+
Logical operators is used to combine boolean values such as logical AND, logical OR, logical NOT.
65+
66+
*Syntax:*
67+
```javascript
68+
&& (logical AND)
69+
|| (logical OR)
70+
! (logical NOT)
71+
```
72+
73+
```javascript
74+
let isSunny = true;
75+
let isWeekend = true;
76+
77+
if (isSunny && isWeekend) {
78+
console.log("It's a party day!");
79+
}
80+
```
81+
82+
### &#10022; Assignment:
83+
Assignment operators is used to assign values to variables such as assignment, addition assignment, subtraction assignment, multiplication assignment, division assignment, modulo assignment.
84+
85+
*Syntax:*
86+
```javascript
87+
= (assignment)
88+
+= (addition assignment)
89+
-= (subtraction assignment)
90+
*= (multiplication assignment)
91+
/= (division assignment)
92+
%= (modulo assignment)
93+
```
94+
95+
```javascript
96+
let salary = 2500;
97+
salary += 500; // salary with increment of 500
98+
```
99+
100+
### &#10022; Ternary:
101+
Ternary operators is used for a shorthand way to write an if-else statement.
102+
103+
*Syntax: `condition ? expression1 : expression2`*
104+
105+
```javascript
106+
let isAdult = age >= 18 ? "Adult" : "Minor";
107+
```
108+
109+
### &#10022; Comparison:
110+
- Arithmetic Operators:
111+
- For mathematical calculations, data manipulation, and creating expressions.
112+
- Comparison Operators:
113+
- For making decisions based on conditions and controlling the flow of your code.
114+
- Logical Operators:
115+
- For combining boolean values and creating complex conditions.
116+
- Assignment Operators:
117+
- For assigning values to variables and updating their values.
118+
- Ternary Operator:
119+
- For concisely writing conditional expressions.
120+
121+
---
122+
[&#8682; To Top](#-operators)
123+
124+
[&#10094; Previous Topic](./data-types.md) &emsp; [Next Topic &#10095;](./control-flow.md)
125+
126+
[&#8962; Goto Home Page](../README.md)

0 commit comments

Comments
 (0)