This is what confuses me alot: Sometimes we invoke a function and sometimes we do not.
To make this more clear:
We make two functions called getString and makeUpperCase:
function getString(string) {
return string
}
function makeUpperCase(neutralString) {
return console.log(getString(neutralString).toUpperCase())
}
makeUpperCase("Books.") // Prints BOOKS.
Here i just made a function called getString, it returns a parameter called string. Then in makeUpperCase function i invoke getString with "Books" as an argument, which will log the argument with UPPERCASE letters. At the end we invoke makeUpperCase function so it will log the text to the console.
Suppose we want to make a promise for an example.
This is just an example:
function executor(resolve, reject) {
resolve("Promise status: resolved")
}
const promise = new Promise(executor)
I am pretty sure most of the people write promises a different way, however this is how i write the promise.
Here we create the promise, but we do not invoke the function, like we just pass the function executor without invoking it.
Like why? I am not sure if i get the point of sometimes invoking a function and sometimes not. What exactly is the point here?