Skip to content

Commit e03288e

Browse files
author
Carlos
committed
Add arithmetic, assignment, comparison, logical, and bitwise operator tables
1 parent c2943b1 commit e03288e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/cheatsheet/basics.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ In JavaScript, you can declare variables using `var`, `let`, and `const` keyword
6464
6565
Arithmetic operators are used to perform mathematical operation:
6666
67+
| Operator | Description | Example | Result |
68+
| -------- | ------------------- | ----------------- | ---------- |
69+
| `+` | Addition | `5 + 2` | `7` |
70+
| `-` | Subtraction | `5 - 2` | `3` |
71+
| `*` | Multiplication | `5 * 2` | `10` |
72+
| `/` | Division | `5 / 2` | `2.5` |
73+
| `%` | Modulus (Remainder) | `5 % 2` | `1` |
74+
| `++` | Increment | `let x = 5; x++;` | `x` is `6` |
75+
| `--` | Decrement | `let x = 5; x--;` | `x` is `4` |
76+
| `**` | Exponentiation | `5 ** 2` | `25` |
77+
78+
6779
1. **Addition (`+`)**: Adds two numbers.
6880
6981
```javascript
@@ -120,6 +132,16 @@ These operators can be used with numbers, variables, or expressions.
120132
121133
Assignment operators are used to assign values to variables:
122134
135+
| Operator | Description | Example | Result |
136+
| -------- | ------------------------- | --------------------- | ----------- |
137+
| `=` | Assignment | `let x = 10;` | `x` is `10` |
138+
| `+=` | Addition assignment | `let x = 5; x += 10;` | `x` is `15` |
139+
| `-=` | Subtraction assignment | `let x = 10; x -= 5;` | `x` is `5` |
140+
| `*=` | Multiplication assignment | `let x = 5; x *= 10;` | `x` is `50` |
141+
| `/=` | Division assignment | `let x = 10; x /= 5;` | `x` is `2` |
142+
| `%=` | Modulus assignment | `let x = 10; x %= 3;` | `x` is `1` |
143+
| `**=` | Exponentiation assignment | `let x = 5; x **= 2;` | `x` is `25` |
144+
123145
1. **Assignment (`=`)**: Assigns the value on the right to the variable on the left.
124146
125147
```javascript
@@ -174,6 +196,17 @@ These operators provide a shorthand way to update the value of a variable in rel
174196
175197
Comparison operators are used to compare two values:
176198
199+
| Operator | Description | Example | Result |
200+
| -------- | ------------------------ | ----------- | ------ |
201+
| `==` | Equal to | `5 == 5` | `true` |
202+
| `!=` | Not equal to | `5 != 4` | `true` |
203+
| `===` | Strictly equal to | `5 === 5` | `true` |
204+
| `!==` | Strictly not equal to | `5 !== '5'` | `true` |
205+
| `>` | Greater than | `10 > 5` | `true` |
206+
| `<` | Less than | `5 < 10` | `true` |
207+
| `>=` | Greater than or equal to | `10 >= 10` | `true` |
208+
| `<=` | Less than or equal to | `5 <= 5` | `true` |
209+
177210
1. **Equal to (`==`)**: Returns true if the operands are equal.
178211
179212
```javascript
@@ -230,6 +263,12 @@ These operators are often used in conditional statements to perform different ac
230263
231264
Logical operators are used to determine the logic between variables or values:
232265
266+
| Operator | Description | Example | Result |
267+
| -------- | ----------- | ----------------- | ------- |
268+
| `&&` | Logical AND | `true && true` | `true` |
269+
| `\|\|` | Logical OR | `true \|\| false` | `true` |
270+
| `!` | Logical NOT | `!true` | `false` |
271+
233272
1. **Logical AND (`&&`)**: Returns true if both operands are true.
234273
235274
```javascript
@@ -257,6 +296,15 @@ These operators are often used in conditional statements to combine or invert bo
257296
258297
Bitwise operators operate on 32-bit binary representations of numbers:
259298
299+
| Operator | Description | Example | Result |
300+
| -------- | ---------------------------- | --------- | ------ |
301+
| `&` | Bitwise AND | `5 & 1` | `1` |
302+
| `^` | Bitwise XOR | `5 ^ 1` | `4` |
303+
| `~` | Bitwise NOT | `~5` | `-6` |
304+
| `<<` | Left shift | `5 << 1` | `10` |
305+
| `>>` | Sign-propagating right shift | `5 >> 1` | `2` |
306+
| `>>>` | Zero-fill right shift | `5 >>> 1` | `2` |
307+
260308
1. **Bitwise AND (`&`)**: Returns a one in each bit position where operands have ones.
261309
262310
```javascript

0 commit comments

Comments
 (0)