I am new learner of Javascript and I got stuck in "functions returned from other functions". The code is as below.
var createScream = function(logger) { return function(message) {
logger(message.toUpperCase() + "!!!")
}
}
const scream = createScream(message => console.log(message))
scream('functions can be returned from other functions')
scream('createScream returns a function')
scream('scream invokes that returned function')
Console output:
"FUNCTIONS CAN BE RETURNED FROM OTHER FUNCTIONS!!!" "CREATESCREAM RETURNS A FUNCTION!!!" "SCREAM INVOKES THAT RETURNED FUNCTION!!!"
Question: why it will work this way? what is the process of executing? Does function scream have any parameter? how does it work?
This may be very easy, I searched but no clear explanation. Can someone please give me a hint or explain the whole execution process in details?
Thanks in advance!