fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
.then(json => console.log(json))
setTimeout(()=>{
console.log("Callback after delay")
},1000)
setTimeout(()=>{
console.log("Callback with no delay")
})
console.log("HI this is test")
It is giving the below output:
HI this is test
Callback with no delay
{userId: 1, id: 1, title: 'delectus aut autem', completed: false}
Callback with delay
As callback in promises goes to microtask queue
then callback in fetch
should be execute first and after that setTimeout code with no delay
and then delay