Skip to content

Commit 4748a5a

Browse files
refactor: table method
1 parent 4ee3e81 commit 4748a5a

File tree

14 files changed

+157
-38
lines changed

14 files changed

+157
-38
lines changed

11_array/4_array_destructuring.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Array Destructure
22

33
// What
4-
// - Array destructuring is a feature in JavaScript that allows you to extract values from an array and assign them to individual variables.
4+
// - Array destructuring is a feature in JavaScript that allows you to extract elements from an array and assign them to individual variables.
55

66
const myArray = [1, 2, 3, 4, 5];
77

13_function/arrow_function.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Arrow Function
22

3-
// SYNTAX
3+
// Syntax
44
// const variableName = () => {
55
// code...
66
// return

25_asynchronous_javascript/1_asynchronous_operation/asynchronous_operation.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Asynchronous Operation
22

3+
Video: https://youtu.be/zgt5oTD3rRc?si=C_v1lcoCLHwkmZD0
4+
35
What
46

57
- An asynchronous operation is a process that starts but doesn't necessarily finish immediately.

25_asynchronous_javascript/call_back/1_call_back.js 25_asynchronous_javascript/3_call_back/1_call_back.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Call Back Function
22

3+
// Video: https://youtu.be/i2SPq-nb3NQ?si=WDJvXblySIo-A9wi
4+
35
// What
46
// - A call back function is a function which passed as an argument to another function.
57
// - Call back function called after the main function completes its execution.

25_asynchronous_javascript/call_back/2_call_back_hell.js 25_asynchronous_javascript/3_call_back/2_call_back_hell.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Call back function
22

3+
// Video
4+
// https://youtu.be/NOlOw03qBfw?si=VFjF1eUuPxogVf1a
35
// https://youtu.be/bx9xYPt2tdc
46

5-
function firstFunction(callback) {
7+
https: function firstFunction(callback) {
68
setTimeout(function () {
79
console.log("First function executed.");
810
callback();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Executor Function
2+
3+
What
4+
5+
- The executor function is a special function passed to the Promise constructor when creating a new Promise object.
6+
- It's responsible for initiating the asynchronous operation and determining whether the Promise should be resolved or rejected.
7+
8+
Why
9+
10+
- The executor function is crucial because it sets up the conditions for the Promise's outcome.
11+
- It typically contains the code that performs the asynchronous task and decides whether the task was successful or failed.
12+
13+
How
14+
15+
- Arguments: The executor function receives two functions as arguments: resolve and reject.
16+
- Asynchronous Operation: Inside the executor, you perform the asynchronous task.
17+
- Resolution or Rejection:
18+
- If the task is successful, call the resolve function with the result as an argument. This fulfills the Promise.
19+
- If the task fails, call the reject function with an error object as an argument. This rejects the Promise.
20+
21+
Example
22+
23+
```javascript
24+
const myPromise = new Promise((resolve, reject) => {
25+
setTimeout(() => {
26+
const data = { name: "John Doe", age: 30 };
27+
resolve(data); // Fulfilling the Promise
28+
}, 2000);
29+
});
30+
```
31+
32+
Note
33+
34+
- The executor function is called immediately when the Promise is created.
35+
- The asynchronous operation within the executor should be performed using asynchronous APIs or techniques (e.g., setTimeout, fetch, XMLHttpRequest).
36+
- The resolve and reject functions should only be called once within the executor.
37+
38+
Analogy
39+
40+
- Think of the executor function as a worker who is tasked with completing a job. The worker performs the job, and then either reports success (resolves the Promise) or failure (rejects the Promise).

25_asynchronous_javascript/5_promise/promise.js

+54-12
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,64 @@
1414
// - Pending: Initial state, neither fulfilled nor rejected.
1515
// - Fulfilled: The operation completed successfully.
1616
// - Rejected: The operation failed.
17-
// - You create a Promise using the Promise constructor, which takes an executor function as an argument. The executor function receives two functions: resolve and reject. You call resolve when the operation is successful, passing the result as an argument. You call reject when the operation fails, passing the error as an argument.
17+
// - You create a Promise using the Promise constructor, which takes an executor function as an argument.
18+
// - The executor function receives two functions: resolve and reject.
19+
// - You call resolve when the operation is successful, passing the result as an argument.You call reject when the operation fails, passing the error as an argument.
1820

1921
// Syntax
20-
// const promise = new Promise((resolve, reject) => {
21-
// // Asynchronous operation here
22-
// if (/* condition for success */) {
23-
// resolve(value);
24-
// } else {
25-
// reject(error);
26-
// }
27-
// });
2822

29-
// Example: 1
23+
// Basic Promise Creation
24+
const myPromise = new Promise((resolve, reject) => {
25+
// Asynchronous operation
26+
// If successful:
27+
resolve(result);
28+
// If unsuccessful:
29+
reject(error);
30+
});
31+
32+
// Chaining Promise
33+
myPromise
34+
.then((result) => {
35+
// Handle successful result
36+
return anotherPromise; // Return another Promise for chaining
37+
})
38+
.then((result2) => {
39+
// Handle result from the second Promise
40+
})
41+
.catch((error) => {
42+
// Handle errors from any of the Promises
43+
});
44+
45+
// Error Handling
46+
myPromise
47+
.then((result) => {
48+
// Handle successful result
49+
})
50+
.catch((error) => {
51+
// Handle errors
52+
});
53+
54+
// Promise.all()
55+
Promise.all([promise1, promise2, promise3])
56+
.then((results) => {
57+
// Handle successful results
58+
})
59+
.catch((error) => {
60+
// Handle errors from all Promises
61+
});
62+
63+
// Promise.race()
64+
Promise.race([promise1, promise2, promise3])
65+
.then((result) => {
66+
// Handle the result from the first Promise that resolves
67+
})
68+
.catch((error) => {
69+
// Handle errors
70+
});
71+
72+
// Example
3073
const promise1 = new Promise(function (resolve, reject) {
31-
// Do async task
32-
// Database call, cryptography, network
74+
// Do async task like a database call, cryptography & network etc.
3375

3476
setTimeout(function () {
3577
console.log("Async task is complete");

2_output/console_table.js

+9
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ const students = [
3131

3232
console.table(students);
3333

34+
// Example: 3
35+
const object = {
36+
key1: "value1",
37+
key2: "value2",
38+
key3: "value3",
39+
};
40+
41+
console.table(object);
42+
3443
// Note
3544
// - console.table() is a helpful debugging tool, but it should not be used for logging or displaying data in a production environment.
3645

4_variable/1_variable.js

+5
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ variable3 = variable4 = variable5 = 1;
2727
let variable6 = 1,
2828
variable7 = 2,
2929
variable8 = 3;
30+
31+
// Note
32+
// - The fact that whenever we declare a variable and assign a value to it, it’s not the variable that holds the value but rather the variable just holds an address in the memory where the initialized value is stored. Further explaining, take for example:
33+
let age = 21;
34+
// - when we use age, it gets replaced with 21, but that does not mean that age contains 21, rather what it means is that the variable age contains the address of the memory location where 21 is stored.

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
5. JavaScript Engine
167167
6. JavaScript Environment
168168
7. Just in time compilation (JIT)
169+
8. Call Stack
169170

170171
12. JavaScript Execution Context
171172

@@ -179,11 +180,12 @@
179180
13. Asynchronous JavaScript
180181
1. Asynchronous Operations
181182
2. setTimeout & setInterval
182-
3. Async and Await
183-
4. Call back
183+
3. Call back
184184
1. Call back function
185185
2. Call back hell
186+
4. Async and Await
186187
5. Promise
188+
1. Executor Function
187189
6. Fetch
188190

189191
<!-- OOP -->

code_test_space.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828

2929
// // promise1;
3030

31-
function myFirst() {
32-
console.log("Hello");
33-
}
34-
35-
function mySecond() {
36-
console.log("Goodbye");
37-
}
38-
39-
mySecond();
40-
myFirst();
31+
const object = {
32+
key1: "value1",
33+
key2: "value2",
34+
key3: "value3",
35+
nestedObject: {
36+
key4: "value4",
37+
key5: "value5",
38+
key6: "value6",
39+
},
40+
};
41+
42+
console.table(object);
+15-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
Compile Time
22

3-
**Compile Time**
3+
Compile Time
4+
5+
What
6+
7+
- Compile time refers to the phase in software development where source code is converted into a machine-readable format. This process is typically performed by a compiler.
8+
9+
Why
410

5-
### What
6-
Compile time refers to the phase in software development where source code is converted into a machine-readable format. This process is typically performed by a compiler.
11+
- Compiling code offers several advantages:
712

8-
### Why
9-
Compiling code offers several advantages:
10-
* **Performance:** Compiled code can execute faster than interpreted code.
11-
* **Efficiency:** Compilers can optimize code for specific hardware and architectures.
12-
* **Portability:** Compiled code can be run on different platforms without needing the original source code.
13+
- **Performance:** Compiled code can execute faster than interpreted code.
14+
- **Efficiency:** Compilers can optimize code for specific hardware and architectures.
15+
- **Portability:** Compiled code can be run on different platforms without needing the original source code.
1316

1417
### How
18+
1519
1. **Parsing:** The compiler breaks down the source code into tokens and analyzes its syntax.
1620
2. **Semantic Analysis:** The compiler checks the code for semantic errors, such as type mismatches or undefined variables.
1721
3. **Code Generation:** The compiler generates machine code or an intermediate representation that can be executed by a virtual machine or interpreter.
1822

1923
### Example
24+
2025
In languages like C++, Java, and C#, the compilation process generates executable files that can be run directly on the target platform.
2126

2227
### Important Note
28+
2329
Not all languages are compiled. Some languages, like JavaScript, are interpreted, meaning the code is executed directly without a compilation step. However, modern JavaScript engines often use Just-In-Time (JIT) compilation to improve performance.
2430

2531
### Analogy
32+
2633
Think of a compiler as a translator who converts a book written in one language (the source code) into another language (machine code) that can be understood by the target audience (the computer).

javascript_under_the_hood/runt_time.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
**Runtime**
1+
Runtime
22

3-
### What
4-
Runtime refers to the period during which a computer program is executing. It's the time when the code is being processed and instructions are carried out.
3+
What
4+
- Runtime refers to the period during which a computer program is executing. It's the time when the code is being processed and instructions are carried out.
55

66
### Why
77
Understanding runtime is crucial for:

pending_concept/notes/terms_explain.md

+6
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,12 @@ Function == Method == Operations == Behaviors
120120

121121
- Functions used to create new objects.
122122

123+
# What is Prase?
124+
- Parsing is the process of taking a JSON string (which is essentially a text format) and converting it into a data structure that your programming language can use (e.g., an object or dictionary).
125+
126+
# What is Serializes?
127+
- In computing, serialization is the process of translating a data structure or object state into a format that can be stored or transmitted and reconstructed later.
128+
123129
# Types of Naming Convention
124130

125131
1. Camel Case: helloWorld

0 commit comments

Comments
 (0)