-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
40 lines (34 loc) · 833 Bytes
/
test.js
File metadata and controls
40 lines (34 loc) · 833 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const url = 'https://jsonplaceholder.typicode.com/users'
// new Promise((resolve,reject)=>{
// setTimeout(()=>{
// console.log("Async completed.")
// resolve({username: "Ainain", age: 22})
// }, 1000)
// })
// .then((response)=>{
// console.log(response)
// })
// let name
// async function consumePromise(){
// try {
// const response = await fetch(url)
// const data = await response.json()
// // console.log(data)
// name = data[0].name
// printName()
// } catch (error) {
// console.log(`Error: ${error}`)
// }
// function printName(){
// console.log(name)
// }
// }
// consumePromise()
fetch(url)
.then((response)=>{
const data = response.json()
return data
})
.then((data)=>{
console.log(data[0].name)
})