#returning functions
4 messages · Page 1 of 1 (latest)
Can you post an example snippet of exactly what you mean? Like this?
function someFunction() {
// like this?
// are you asking why the anonymous function below can be returned without naming it?
return ((a, b) => {
console.log(`sum is: ${a + b}`);
});
}
const f = someFunction();
f(2, 3);
If so, I believe the answer might be because functions in JavaScript are first-class citizens, so they behave just like Numbers, Strings, etc.? e.g. When you return a Number from a function, you can just do return 42; rather than const value = 42; return value;.
oh, i just found out about anonymous functions. that's what i was describing and i didn't know it. thanks ❤️