Hey! I'm YCMJason, a Software Engineer in London 👨💻. Love diving into tech puzzles and sharing them! 🧩
All views expressed here are my own opinions, so please take them with a pinch of salt! 🧂
Thanks for your comments! I am not sure if I understand your question correctly.
But it sounds like you are confused with the idea of "functions as first-class citizens", which is a fancy way of saying you can pass functions as a values around.
Are you familiar with setTimeout? Have a read about it here.
Consider
setTimeout(function(){print('hello')},3000);
We are passing a function function () { print('hello'); } to setTimeout as the first argument. So if we call that function f, then we can equivilantly pass f to setTimeout.
Thanks for your comments! I am not sure if I understand your question correctly.
But it sounds like you are confused with the idea of "functions as first-class citizens", which is a fancy way of saying you can pass functions as a values around.
Are you familiar with
setTimeout
? Have a read about it here.Consider
We are passing a function
function () { print('hello'); }
tosetTimeout
as the first argument. So if we call that functionf
, then we can equivilantly passf
tosetTimeout
.So in another words, my code:
Is basically equivalent to:
It is also important to note that the following is incorrect (or not the same):
Because Javascript will first evaluate
resolve()
and use the value it returns to pass on tothen
.I hope I did help a little.