0

So I was just going through how event loop works and how it decides call back priority . I conducted two experiments : Experiment 1 :

Promise.resolve().then(()=>
{
    console.log('promise resolved')
})
process.nextTick(()=>
{
    console.log('next tick')
})

gives expected output but Experiment 2: same as above but added package.json

{
  "name": "nodelearn",
  "version": "1.0.0",
  "description": "",
  "type":"module",
  "main": "hello.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

experiment 1 gives the correct result(expected):

next tick
promise resolved

but experiment 2 gives unexpected result:

promise resolved
next tick

next tick callback should be executed first.

ayush
  • 1
  • 1

0 Answers0