Skip to content

Commit 99e18ba

Browse files
committed
Fetch - Big Picture
1 parent c822fc7 commit 99e18ba

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

app.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22
// promised based
33
// XHR is not wrong, you can complete all our upcoming examples and projects using XHR. Fetch is just alternative approach that has simpler and cleaner syntax. The end result is the same.Still get dynamically, behind the scenes.
44

5-
const url = "./api/people.jsons";
5+
const url = "./api/people.json";
66

7-
/* Using Implicit Return */
7+
/* Fetch is a builtin functionality that makes to do less work for setup so we can start implementating */
88
fetch(url)
99
.then((response) => console.log(response))
1010
.then((data) => console.log(data))
1111
.catch((error) => console.log(error));
12+
13+
const promise = new Promise((resolve, reject) => {
14+
let value = false;
15+
if (value) {
16+
resolve([1, 2, 5]);
17+
} else {
18+
reject(new Error(`The value is ${value}`));
19+
}
20+
return promise;
21+
});
22+
23+
promise.then((data) => console.log(data)).catch((error) => console.log(error));

0 commit comments

Comments
 (0)