Skip to content

Commit de89de4

Browse files
committed
Merge branch 'main' into working-with-JS-frameworks
2 parents 32ab8ff + 1a98546 commit de89de4

File tree

26 files changed

+2353
-10
lines changed

26 files changed

+2353
-10
lines changed

Advanced-DOM-APIs/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,4 +446,8 @@ try {
446446
}
447447
```
448448

449-
In this example, a custom `Error` object is created by extending the `Error` class and adding a custom name. The error is then thrown and caught using a `try...catch` statement, just like before.
449+
In this example, a custom `Error` object is created by extending the `Error` class and adding a custom name. The error is then thrown and caught using a `try...catch` statement, just like before.
450+
451+
* * *
452+
453+
[<img align="center" src="../images/left_arrow.png" height="20" width="20"/> Constructor Functions and Prototypes](../Constructor-Functions-and-Prototypes/README.md)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [<img align="center" src="../images/home.png" height="20" width="20"/> Home](../README.md) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Working with Events <img align="center" src="../images/right_arrow.png" height="20" width="20"/>](../Working-with-Events/README.md)

Advanced-Function-Concepts/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,8 @@ As a consequence, it was hard to control where variables were available. Variabl
188188
console.log(age); // Error: "age is not defined"
189189
```
190190

191-
Not something you see too often but something that is possible.
191+
Not something you see too often but something that is possible.
192+
193+
* * *
194+
195+
[<img align="center" src="../images/left_arrow.png" height="20" width="20"/> Working with Events](../Working-with-Events/README.md)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [<img align="center" src="../images/home.png" height="20" width="20"/> Home](../README.md) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[More on Numbers and Strings <img align="center" src="../images/right_arrow.png" height="20" width="20"/>](../More-on-Numbers-and-Strings/README.md)

Async-JS-Promises-and-Callbacks/README.md

Lines changed: 1001 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const button = document.querySelector('button');
2+
const output = document.querySelector('p');
3+
4+
// Wrapping setTimeout() inside `setTimer()` function and it returns Promise object.
5+
// This Promise object will now handle the success or failure outcomes.
6+
// So, point here is, since these web API methods (setTimeout() and navigator.geolocation.getCurrentPosition())
7+
// does not support Promise object but only callbacks, hence, for demonstration, they are encapsulated under
8+
// Promise object.
9+
10+
const getPosition = (opts) => {
11+
const promise = new Promise((resolve, reject) => {
12+
navigator.geolocation.getCurrentPosition(success => {
13+
resolve(success);
14+
}, error => {
15+
reject(error);
16+
}, opts);
17+
});
18+
return promise;
19+
};
20+
21+
const setTimer = (duration) => {
22+
const promise = new Promise((resolve, reject) => {
23+
setTimeout(() => {
24+
resolve('Done!');
25+
}, duration);
26+
});
27+
return promise;
28+
};
29+
30+
async function trackUserHandler() {
31+
// let positionData;
32+
let posData;
33+
let timerData;
34+
try {
35+
posData = await getPosition();
36+
timerData = await setTimer(2000);
37+
} catch(error) {
38+
console.log(error);
39+
}
40+
console.log(timerData, posData);
41+
// .then(posData => {
42+
// positionData = posData;
43+
// return setTimer(2000);
44+
// })
45+
// .catch(err => {
46+
// console.log(err);
47+
// })
48+
// .then(data => {
49+
// console.log(data, positionData);
50+
// });
51+
52+
// setTimer(1000).then(() => {
53+
// console.log('Timer Done!');
54+
// });
55+
// console.log("Getting position...");
56+
}
57+
58+
button.addEventListener('click', trackUserHandler);
59+
// let result = 0;
60+
61+
// for (let i = 0; i < 100000000; i++) {
62+
// result += i;
63+
// }
64+
65+
// console.log(result);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Async Code</title>
8+
<script src="app.js" defer></script>
9+
</head>
10+
<body>
11+
<button>Track Me!</button>
12+
<p></p>
13+
</body>
14+
</html>

Basics/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,4 +904,8 @@ There are different algorithms used for garbage collection, such as *reference c
904904

905905
- Use `setTimeout` or `setInterval` with care, as they can cause memory leaks if not used properly. It's important to clear these timers when they are no longer needed.
906906

907-
By following these best practices, you can ensure that your JavaScript code is efficient and free from memory leaks.
907+
By following these best practices, you can ensure that your JavaScript code is efficient and free from memory leaks.
908+
909+
* * *
910+
911+
[<img align="center" src="../images/left_arrow.png" height="20" width="20"/> Introduction](../Introduction/README.md)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [<img align="center" src="../images/home.png" height="20" width="20"/> Home](../README.md) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Working with Control Structures <img align="center" src="../images/right_arrow.png" height="20" width="20"/>](../Control-Structures/README.md)

Classes-and-Object-Oriented-Programming/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,4 +524,8 @@ Readings:
524524

525525
- [JavaScript — Property Descriptor](https://codeburst.io/javascript-object-property-attributes-ac012be317e2)
526526

527-
- [JavaScript Property Descriptors](https://flaviocopes.com/javascript-property-descriptors/)
527+
- [JavaScript Property Descriptors](https://flaviocopes.com/javascript-property-descriptors/)
528+
529+
* * *
530+
531+
[<img align="center" src="../images/left_arrow.png" height="20" width="20"/> More on Objects](../More-on-Objects/README.md)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [<img align="center" src="../images/home.png" height="20" width="20"/> Home](../README.md) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Constructor Functions and Prototypes <img align="center" src="../images/right_arrow.png" height="20" width="20"/>](../Constructor-Functions-and-Prototypes/README.md)

Constructor-Functions-and-Prototypes/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ As we know, this is going to fail since there is no such method `printRating()`
312312
Now, since the object is already created, we would want to adjust it's prototype. We can do this by using global [`Object`](https://developer.mozilla.org/en-US/docs/Glossary/Global_object) method [`setPrototypeOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf).
313313

314314
```javascript
315-
Object.setPropertyOf(course, {
315+
Object.setPrototypeOf(course, {
316316
printRating: function(){
317317
console.log(`${this.rating}/5`);
318318
}
@@ -388,3 +388,7 @@ console.log(myObject.b); // outputs 2
388388
```
389389

390390
In this example, we create a new object called `myPrototype` with a property `a` set to `1`. We then create a new object called `myObject` using `Object.create()`, passing in `myPrototype` as the prototype object. We then use `Object.defineProperties()` to define the `b` property of `myObject` with a value of `2` and a `writable` property set to `true`. We can then access the `b` property of `myObject`, which outputs `2`.
391+
392+
* * *
393+
394+
[<img align="center" src="../images/left_arrow.png" height="20" width="20"/> Classes and Object Oriented Programming (OOP)](../Classes-and-Object-Oriented-Programming/README.md)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [<img align="center" src="../images/home.png" height="20" width="20"/> Home](../README.md) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[Advanced DOM APIs <img align="center" src="../images/right_arrow.png" height="20" width="20"/>](../Advanced-DOM-APIs/README.md)

Control-Structures/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,7 @@ Readings:
223223
- [JavaScript try...catch...finally Statement](https://www.programiz.com/javascript/try-catch-finally)
224224
225225
- [JavaScript throw Statement](https://www.programiz.com/javascript/throw)
226+
227+
* * *
228+
229+
[<img align="center" src="../images/left_arrow.png" height="20" width="20"/> Basic](../Basics/README.md)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [<img align="center" src="../images/home.png" height="20" width="20"/> Home](../README.md) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[More on Functions <img align="center" src="../images/right_arrow.png" height="20" width="20"/>](../More-on-Functions/README.md)

DOM/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,4 +1040,8 @@ Just use:
10401040
10411041
```javascript
10421042
someElement.textContent = someElement.textContent + 'More text!';
1043-
```
1043+
```
1044+
1045+
* * *
1046+
1047+
[<img align="center" src="../images/left_arrow.png" height="20" width="20"/> More on Functions](../More-on-Functions/README.md)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [<img align="center" src="../images/home.png" height="20" width="20"/> Home](../README.md) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[More on Arrays and Iterables <img align="center" src="../images/right_arrow.png" height="20" width="20"/>](../More-on-Arrays-and-Iterables/README.md)

0 commit comments

Comments
 (0)