I am reading a book Mostly adequate guide and in the chapter about First Class functions, I have come across this example. Can somebody explain it to me?
It says the below two lines are equal.
// ignorant
const getServerStuff = callback => ajaxCall(json => callback(json));
// enlightened
const getServerStuff = ajaxCall;
Here is the reason both are equivalent:
// this line
ajaxCall(json => callback(json));
// is the same as this line
ajaxCall(callback);
// so refactor getServerStuff
const getServerStuff = callback => ajaxCall(callback);
// ...which is equivalent to this
const getServerStuff = ajaxCall; // <-- look mum, no ()'s
But I can't undertand this part. How are these two equivalent?
// this line
ajaxCall(json => callback(json));
// is the same as this line
ajaxCall(callback);
Can someone please explain it in layman terms?