I am new to asynchronous JavaScript and I have been learning how to fetch data from 3rd party APIs. While on it, I came across a small issue:
const users = fetch('https://jsonplaceholder.typicode.com/users')
.then((res) => { // <--- with curly braces
res.json()
})
.then((data) => {
console.log(data)
})
const users = fetch('https://jsonplaceholder.typicode.com/users')
.then((res) => res.json()) // <--- without curly braces
.then((data) => {
console.log(data)
})
With the curly braces, I got the result as undefined
.
Whereas without the curly braces, I get the entire data.
How and why is this possible? Has anybody come across this situation before?