This is a stupid question but I'm having a hard time understanding how functions are first-class citizens in javascript and when callbacks are called.
const promise = new Promise((resolve,reject) => {
const error = false
if(!error) {
resolve("Promise resolved")
} else {
reject("Promise is rejected")
}
})
console.log(promise) //Promise { 'Promise resolved' }
For the code above why does the callback inside the promise (resolve, reject) => {} get called when I create a Promise? Is this something in the constructor of the Promise class? I cannot understand why it is being called immediately.